【问题标题】:Linkedin scraper to extract skillsLinkedin刮刀提取技能
【发布时间】:2020-05-25 19:25:57
【问题描述】:

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

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

【问题讨论】:

  • 你能分享一个HTML技能示例吗?

标签: python selenium webdriver parsel


【解决方案1】:

为了获取所有技能,您需要先展开技能部分,使其显示所有技能,然后定位名称以“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)

【讨论】:

    猜你喜欢
    • 2021-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多