Linkedin请求使用代理

时间:2017-09-06 12:02:18

标签: python python-requests

我的国家/地区已被封锁,因此我正在尝试使用代理登录。

import requests
from bs4 import BeautifulSoup
p = {'http': 'http://54.167.184.222:3128', 'https': 'https://54.167.184.222:3128'}

client = requests.Session()
client.proxies.update(p)

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

html = client.get(HOMEPAGE_URL).content
soup = BeautifulSoup(html)
csrf = soup.find(id="loginCsrfParam-login")['value']

login_information = {
    'session_key':'Login',
    'session_password':'Password',
    'loginCsrfParam': csrf,
}

client.post(LOGIN_URL, data=login_information)

但是我收到以下错误:

Traceback (most recent call last):
  File "/home/afanasev/linkedin/lib/python3.6/site-packages/requests/adapters.py", line 324, in send
    timeout=timeout
  File "/home/afanasev/linkedin/lib/python3.6/site-packages/requests/packages/urllib3/connectionpool.py", line 506, in urlopen
    raise SSLError(e)
requests.packages.urllib3.exceptions.SSLError: hostname '54.167.184.222' doesn't match either of 'www.linkedin.com', 'linkedin.com'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/afanasev/PycharmProjects/linkedin/test.py", line 12, in <module>
    html = client.get(HOMEPAGE_URL).content
  File "/home/afanasev/linkedin/lib/python3.6/site-packages/requests/sessions.py", line 394, in get
    return self.request('GET', url, **kwargs)
  File "/home/afanasev/linkedin/lib/python3.6/site-packages/requests/sessions.py", line 382, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/afanasev/linkedin/lib/python3.6/site-packages/requests/sessions.py", line 485, in send
    r = adapter.send(request, **kwargs)
  File "/home/afanasev/linkedin/lib/python3.6/site-packages/requests/adapters.py", line 379, in send
    raise SSLError(e)
requests.exceptions.SSLError: hostname '54.167.184.222' doesn't match either of 'www.linkedin.com', 'linkedin.com'

我之前从未在python中使用过代理,我不明白这里有什么问题。我在firefox中检查了代理 - 它是有效的。

0 个答案:

没有答案