0
是python中的新手。提取下面的代碼從在線帖子登錄到網站,但出現錯誤。如何修復這個執行登錄網站的python代碼
請幫忙解決這個問題,並說明將幫助我
import requests
with requests.Session() as c:
EMAIL = '[email protected]'
PASSWORD = '[email protected]'
URL = 'https://www.linkedin.com/'
c.get(URL)
token = c.cookies['CsrfParam']
# This is the form data that the page sends when logging in
login_data = {loginCsrfParam:token, session_key:EMAIL, session_password:PASSWORD}
# Authenticate
r = c.post(URL, data=login_data)
# Try accessing a page that requires you to be logged in
r = c.get('https://www.linkedin.com/feed/')
print r.content
我堅持下面的錯誤:
C:\Python27>python website.py
Traceback (most recent call last):
File "website.py", line 8, in <module>
token = c.cookies['CsrfParam']
File "C:\Python27\lib\site-packages\requests\cookies.py", line 329, in __getitem__
return self._find_no_duplicates(name)
File "C:\Python27\lib\site-packages\requests\cookies.py", line 400, in _find_no_duplicates
raise KeyError('name=%r, domain=%r, path=%r' % (name, domain, path))
KeyError: "name='CsrfParam', domain=None, path=None"
嗨!我跑出它令牌。它沒有顯示任何錯誤,但它並沒有打開網頁。我希望此代碼打開網頁並使用提供的憑據登錄。 –
我已經嘗試了很多與請求的變化,我不能得到它的工作。根據我的經驗,Selenium傾向於使用反編程系統,因此可能需要查看此文章:https://www.quora.com/How-do-I-log-into-Quora-using-Python-since-they -dont-have-an-API。另外還有一個Quora模塊:https://pypi.python.org/pypi/quora/但是這不會登錄,所以它可能沒有你需要的功能。對不起,我忍不住了。 – TLOwater