스크립트가 텍스트 파일에 저장된 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()?)
'br [ 'txtParm'] = x'와 같은 문장을 사용할 수 없다는 것은'mechanize.Browser' 객체가 색인 할 수 없기 때문이라고 생각합니다. – martineau