Python 脚本在刮取多个值时抛出错误
我的脚本试图从一个网站中获取80000个存储在文本文件中的ID。当我用一个o/p运行代码时,它运行得很好,但是当我把所有的输入放在一个循环中时,我得到了一个错误 我的代码:Python 脚本在刮取多个值时抛出错误,python,python-2.7,web-scraping,beautifulsoup,mechanize,Python,Python 2.7,Web Scraping,Beautifulsoup,Mechanize,我的脚本试图从一个网站中获取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 f
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.\u mechanize.Browser实例没有属性\u\u setitem\uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu!将其放置在mechanize浏览器下方,然后在末尾放置一个try catch。它会起作用的。一旦你尝试了注释,它就会起作用。我认为这个错误意味着你不能使用像br['txtParm']=x这样的语句,因为mechanize.Browser
对象是不可索引的。