【问题标题】:How to scrape employee counts from a LinkedIn company page using Selenium?如何使用 Selenium 从 LinkedIn 公司页面中抓取员工人数?
【发布时间】:2019-12-05 04:43:52
【问题描述】:

我正在尝试构建一个搜索行业名称的程序,然后单击 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)

【问题讨论】:

  • 你不......这违反了他们的服务条款。

标签: python selenium selenium-chromedriver


【解决方案1】:

使用下面的 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

截图:

【讨论】:

    猜你喜欢
    • 2021-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-21
    • 2022-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多