我的脚本正在尝试搜索存储在文本文件中的80000个ID的网站。当我使用单个o / p运行我的代码时,它运行正常,但是当我将所有输入放在循环中时,我收到错误。
我的代码:
from bs4 import BeautifulSoup
import mechanize
br = mechanize.Browser()
response = br.open("https://www.matsugov.us/myproperty")
for form in br.forms():
if form.attrs.get('name') == 'frmSearch':
br.form = form
break
br.form['ddlType']=["taxid"]
with open("names.txt") as ins:
tx = ins.read().splitlines()
for x in tx:
br['txtParm'] = x
req = br.submit().read()
soup = BeautifulSoup(req, 'html.parser')
table = soup.find('td', {'class': 'Grid_5'})
for row in table:
print row
错误:
AttributeError: mechanize._mechanize.Browser instance has no attribute __setitem__ (perhaps you forgot to .select_form()?)
答案 0 :(得分:1)
你错了!将它放在机械化浏览器下面,然后在最后放置一个try catch。它会工作。评论一旦你尝试,它的确有效。