python - 登录 linkedin

标签 python python-requests

我只是尝试使用 Linkedin 进行简单的 POST

client = requests.Session()
URL = 'https://www.linkedin.com/uas/login-submit'
login_information = {
    'session_key':'login_email_address',
    'session_password':'password',
}

client.post(URL, data=login_information)

但是我收到了这个回复

Request Error
We’re sorry, there was a problem with your request. Please make sure you have cookies enabled and try again.

Or follow this link to return to the home page.

有什么想法吗?

最佳答案

我觉得用一个简单的POST登录LinkedIn并不是那么容易。试试这个:

import requests
from bs4 import BeautifulSoup

# Get login form
URL = 'https://www.linkedin.com/uas/login'
session = requests.session()
login_response = session.get('https://www.linkedin.com/uas/login')
login = BeautifulSoup(login_response.text)

# Get hidden form inputs
inputs = login.find('form', {'name': 'login'}).findAll('input', {'type': ['hidden', 'submit']})

# Create POST data
post = {input.get('name'): input.get('value') for input in inputs}
post['session_key'] = 'username'
post['session_password'] = 'password'

# Post login
post_response = session.post('https://www.linkedin.com/uas/login-submit', data=post)

# Get home page
home_response = session.get('http://www.linkedin.com/nhome')
home = BeautifulSoup(home_response.text)

这是我之前尝试过的代码,它有效。如果有任何问题请告诉我。

关于python - 登录 linkedin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25753814/

相关文章:

python - 在 Python 中连接短字符串的最佳方法

python - 如何为 Python matplotlib.animation 添加随时间变化的标题?

python - 无法使用请求从网页中获取表格内容

python - 如何使用代理服务器(如 luminati.io)正确地向 https 发出请求?

python - 将 requests.models.Response 转换为 Django HttpResponse

python - Notepad++ 找不到文件路径

python - 如何从文本文件中获取代理ip和端口

python - 您甚至如何提供(openFST 制作的)FST 输入?输出到哪里去?

python - 使用 Python requests 库获取带有 cookie 的页面

python - pyinstaller编译的文件有ssl问题,错误: 185090050