我正在尝试构建一个程序来搜索行业名称,然后单击LinkedIn上结果列表中的第一个配置文件,并刮擦确切的员工人数。我为此写了代码,以为可以,但是我似乎无法理解为什么代码没有返回确切的员工人数。 xpath似乎是正确的-所有帮助都将不胜感激!
import time
import re
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from bs4 import BeautifulSoup
driver = webdriver.Chrome()
driver.get('https://www.linkedin.com/login')
nameidElem = driver.find_element_by_id('username')
nameidElem.send_keys('username_here')
pwdidElem = driver.find_element_by_id('password')
pwdidElem.send_keys('password_here')
continueElem = driver.find_element_by_class_name("btn__primary--large")
result = continueElem.submit()
time.sleep(10)
industry = "books"
link = "https://www.linkedin.com/search/results/companies/?keywords=" +
industry + "&origin=GLOBAL_SEARCH_HEADER"
driver.get(link)
firstcompany = driver.find_element_by_class_name("search-result__title")
firstcompany.click()
employees = driver.find_elements_by_xpath('//*[@id="ember1274"]')
number = re.findall(r'\d', employees.text)
print(number)