スクリプトがテキストファイルに格納されている80000個のIDのWebサイトをスクラップしようとしています。単一の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()?)
私は、 'br ['txtParm'] = x'のようなステートメントは' mechanize.Browser'オブジェクトがインデックスできないので使用できないと思います。 – martineau