如何从我的网络连接的Linkedin上抓取数据?

时间:2018-10-23 05:38:55

标签: python selenium-webdriver beautifulsoup

如何从我的网络连接的Linkedin上抓取数据? 我已成功从单个网址https://www.linkedin.com/in/ $ yourfriendname /

中删除了pereson的名称

有什么办法刮 https://www.linkedin.com/mynetwork/invite-connect/connections/

from selenium import webdriver
from bs4 import BeautifulSoup
import getpass
import requests
from selenium.webdriver.common.keys import Keys
import pprint

chrome_path = '/usr/bin/chromedriver'
driver = webdriver.Chrome(chrome_path)
driver.get("https://www.linkedin.com")
userid='xxxx@gmail.com'
password = ('xxxxxxxx')
driver.implicitly_wait(6)
driver.find_element_by_xpath("""//*[@id="login- 
email"]""").send_keys(userid)
driver.find_element_by_xpath("""//*[@id="login- 
password"]""").send_keys(password)
driver.find_element_by_xpath("""//*[@id="login-submit"]""").click()
url='www.linkedin.com/in/$yourfriendname/'  
driver.get("https://"+url.rstrip())
connectionName = driver.find_element_by_class_name('pv-top-card- 
section__name').get_attribute('innerHTML')
print(connectionName)

>>YOUR FRIEND NAME

url1='https://www.linkedin.com/mynetwork/invite-connect/connections/'
driver.get(url1.rstrip())

如何从url1上方抓取?

1 个答案:

答案 0 :(得分:0)

以下是扩展href标签的代码

url1='https://www.linkedin.com/mynetwork/invite-connect/connections/'
driver.get(url1.rstrip())
elems = driver.find_elements_by_xpath("//div[@class='mn-connection-card__details']//a[@data-control-name='connection_profile'][@href]")

for elem in elems:
    driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
    print (elem.get_attribute("href"))