python - Linkedin 抓取工具提取技能

标签 python selenium webdriver parsel

我正在尝试抓取人们的公开资料,以获取某些角色的最常见技能。我能够提取电子邮件、公司、姓名、职位等,但我无法获得技能。 我正在使用 parsel 中的选择器。我尝试了很多方法,但显然我的目标是错误的类别,我可能应该循环遍历技能。这是到目前为止我的代码:

def linkedin_scrape(linkedin_urls):

profiles = []

for url in linkedin_urls:

    _DRIVER_CHROME.get(url)
    sleep(5)

    selector = Selector(text=_DRIVER_CHROME.page_source)

    # Use xpath to extract the exact class containing the profile name
    name = selector.xpath('//*[starts-with(@class, "inline")]/text()').extract_first()
    if name:
        name = name.strip()

    # Use xpath to extract the exact class containing the profile position
    position = selector.xpath('//*[starts-with(@class, "mt1")]/text()').extract_first()

    if position:
        position = position.strip()
        position = position[0:position.find(' at ')]

    # Use xpath to extract the exact class containing the profile company
    company = selector.xpath('//*[starts-with(@class, "text-align-left")]/text()').extract_first()

    if company:
        company = company.strip()

    # Use xpath to extract skills

    skills = selector.xpath('//*[starts-with(@class, "pv-skill")]/text()').extract_first()

    if skills:
        skills = skills.strip()


    profiles.append([name, position, company, url])
    print(f'{len(profiles)}: {name}, {position}, {company}, {url}, {skills}')

return profiles

最佳答案

为了捕获所有技能,您需要首先展开技能部分,以便它显示所有技能,然后定位名称以“pv-skill-category-entity__name-text”开头的类别。

直到今天这对我都有效。

#locate link to expand skills
show_more_skills_button = driver.find_element_by_class_name("pv-skills-section__chevron-icon")
#expand
show_more_skills_button.click()

skills = driver.find_elements_by_xpath("//*[starts-with(@class,'pv-skill-category-entity__name-text')]")

#create skills set
skill_set = []
for skill in skills:
    skill_set.append(skill.text)

关于python - Linkedin 抓取工具提取技能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62009351/

相关文章:

python - 如何使用 lambda 搜索多个单词

python - 通过命令行传递 Python 变量?

python - 在 Python 中匹配两条特定行之间的行的正则表达式

python - 如何同步 Django 的 'Client' 和 Selenium 的 webdriver 之间使用的 html/session

java - Selenium Webdriver 中的前端数据验证

c# - 在 C# 中配置 BrowserMobProxy

python - 导入错误 : No module named 'selenium'

python - 打印当前日志记录级别

java - 使用 Selenium(2.46 及更高版本)以编程方式下载文件

python - 如何修复 "element not interactable"异常?