0
你好,我創建一個登錄腳本,我有一個錯誤錯誤登錄腳本對象有沒有屬性「__getitem__」
我的代碼
# -*- coding: UTF-8 -*-
from bs4 import BeautifulSoup
import requests
import sys
import os
#givenURL = sys.argv[1]
headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'}
# initialize session
session = requests.Session()
response = session.get("http://website.fr/", headers=headers)
soup = BeautifulSoup(response.content)
token = soup.find('a', {'name':'return'})['value']
token2 = soup.find('a', {'type':'hidden'})['name']
print token token2
誤差
File "logins", line 17, in <module>
token = soup.find('a', {'name':'return'})['value']
TypeError: 'NoneType' object has no attribute '__getitem__'
信息令牌登錄
<input type="hidden" name="return" value="sommetoken=" />
<input type="hidden" name="sommetoken" value="1" /></form>
你好,我測試,它不工作,我想知道我犯了一個錯誤 – parcal 2015-04-02 04:08:10
不清楚 - 似乎爲我工作 – jwilner 2015-04-02 04:31:40
它適用於本地的HTML我太......,如此怪異 – parcal 2015-04-02 04:53:22