私はこのエラーを回避しようとしています:ItemNotFoundError: insufficient items with name u'No_Thanks'
try..exceptステートメントを使用してエラーを発生させます。ただし、次のような別のエラーが発生しますNameError: name 'ItemNotFoundError' is not defined
。なぜこれが起こっているのかわかりません。ありがとう。これが私が使用しているコードです
br = mechanize.Browser()
br.addheaders = [('User-agent', 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1;Trident/5.0)')]
urls = "http://shop.o2.co.uk/mobile_phone/pay_monthly/init/Samsung/Galaxy_Ace_Purple"
r = br.open(urls)
page_child = br.response().read()
soup_child = BeautifulSoup(page_child)
contracts = [tag_c['value']for tag_c in soup_child.findAll('input', {"name": "tariff-duration"})]
data_usage = [tag_c['value']for tag_c in soup_child.findAll('input', {"name": "allowance"})]
for contract in contracts:
if contract <>"Pay_and_Go":
for data in data_usage:
br.select_form('formDuration')
br.form['tariff-duration']=[contract,]
try:
br.form['allowance']=[data,]
except ItemNotFoundError:
continue
br.submit()
page_child_child = br.response().read()
soup_child_child = BeautifulSoup(page_child_child)
items = soup_child_child.findAll('div', {"class": "n-pay-today"})