【问题标题】:scraping linkedin profile without selenium and API在没有硒和 API 的情况下抓取linkedin 配置文件
【发布时间】:2020-12-11 22:40:43
【问题描述】:

我想通过 URL 抓取 LinkedIn 的个人资料

喜欢; https://www.linkedin.com/in/andrew-marson-90a74015/

我想从中获取一些数据

我以前使用过 selenum,但我想让它更快

所以我想使用 request.get(url, auth=**** ) 但是要获取您需要登录的数据,我可以通过 auth = ('user', 'pass')

获取页面
import requests
from requests.auth import HTTPBasicAuth
test = requests.get('https://www.linkedin.com/in/andrew-marson-90a74015/', auth=HTTPBasicAuth('user', 'pass'))
print(test.text)

【问题讨论】:

  • ...没有 selenium 和 API... 为什么要标记selenium
  • 也许有人知道原因
  • 如果您添加任何其他标记,即使是语言绑定 javaPython 等,也可以是 True

标签: selenium web-scraping scrapy scrape


【解决方案1】:
import requests
from bs4 import BeautifulSoup

email = ""
password = ""

client = requests.Session()

HOMEPAGE_URL = 'https://www.linkedin.com'
LOGIN_URL = 'https://www.linkedin.com/uas/login'

html = client.get(HOMEPAGE_URL).content
soup = BeautifulSoup(html, "html.parser")
csrf = soup.find('input', {'name': 'loginCsrfParam'}).get('value')

login_information = {
    'session_key': email,
    'session_password': password,
    'loginCsrfParam': csrf,
    'trk': 'guest_homepage-basic_sign-in-submit'
}

client.post(LOGIN_URL, data=login_information)

response = client.get('https://www.linkedin.com/in/andrew-marson-90a74015/')
print(response.text)

此代码无效

【讨论】:

    【解决方案2】:

    使用beautifulsoup 或scrapy,两者都适用于不需要硒的任务。

    from requests import Session
    from bs4 import BeautifulSoup as bs
    
    with Session() as s:
        site = s.get("https://www.linkedin.com/")
        bs_content = bs(site.content, "html.parser")
        token = bs_content.find("input", {"name": "loginCsrfParam"})["value"]
        login_data = {"username": "admin",
                      "password": "12345", "loginCsrfParam": token}
        s.post("https://www.linkedin.com/login", login_data)
        home_page = s.get("https://www.linkedin.com/")
        print(home_page.content)
    

    【讨论】:

    • linkedin 没有 javascipte 和更改 dom ...如何通过 request.get(url) 登录的问题
    • 我修改了答案看看它,我无法尝试,因为我在linkedin中没有帐户。所以我无法正确测试它
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-08-13
    • 1970-01-01
    • 2021-08-07
    • 1970-01-01
    • 2019-08-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多