Python 如何使用Selenium从LinkedIn公司页面中获取员工数量?
我正试图建立一个程序,搜索一个行业名称,然后点击LinkedIn结果列表中的第一个个人资料,并获取准确的员工人数。我为它编写了代码,我认为这会起作用,但我似乎不明白为什么代码没有返回准确的员工人数。xpath似乎是正确的-任何帮助都会被真正吸引Python 如何使用Selenium从LinkedIn公司页面中获取员工数量?,python,selenium,selenium-chromedriver,Python,Selenium,Selenium Chromedriver,我正试图建立一个程序,搜索一个行业名称,然后点击LinkedIn结果列表中的第一个个人资料,并获取准确的员工人数。我为它编写了代码,我认为这会起作用,但我似乎不明白为什么代码没有返回准确的员工人数。xpath似乎是正确的-任何帮助都会被真正吸引 import time import re from selenium import webdriver from selenium.webdriver.common.keys import Keys from bs4 import BeautifulS
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)
使用下面的xpath获取员工数量
//*[.='Company size']/following-sibling::*[contains(.,'employees')]
截图:
确保在单击firstCompany链接后等待元素显示
编辑1:
使用以下xpath“查看LinkedIn上的所有XX员工”
//a[@data-control-name='topcard_see_all_employees']/span
CSS:
截图:
您不需要。。。这与他们的目标背道而驰。
a[data-control-name='topcard_see_all_employees'] span