gpt4 book ai didi

Python Mechanize : Traceback in br. submit()

转载 作者:行者123 更新时间:2023-12-04 16:21:19 26 4
gpt4 key购买 nike

我在运行代码时遇到了 Mechanize 问题,我不知道问题出在哪里,也许有人可以帮助我。

> ******************************************************
Traceback (most recent call last):
File "D:\Python\web_scrapping\mecha_2.py", line 126, in <module>
br.submit()
File "C:\Python27\lib\site-packages\mechanize\_mechanize.py", line 541, in submit
return self.open(self.click(*args, **kwds))
File "C:\Python27\lib\site-packages\mechanize\_mechanize.py", line 530, in click
request = self.form.click(*args, **kwds)
File "C:\Python27\lib\site-packages\mechanize\_form.py", line 2999, in click
self._request_class)
File "C:\Python27\lib\site-packages\mechanize\_form.py", line 3201, in _click
return control._click(self, coord, return_type, request_class)
File "C:\Python27\lib\site-packages\mechanize\_form.py", line 2350, in _click
r = form._switch_click(return_type, request_class)
File "C:\Python27\lib\site-packages\mechanize\_form.py", line 3269, in _switch_click
req_data = self._request_data()
File "C:\Python27\lib\site-packages\mechanize\_form.py", line 3251, in _request_data
for ii, k, v, control_index in self._pairs_and_controls():
File "C:\Python27\lib\site-packages\mechanize\_form.py", line 3217, in _pairs_and_controls
for ii, key, val in control._totally_ordered_pairs():
File "C:\Python27\lib\site-packages\mechanize\_form.py", line 2138, in _totally_ordered_pairs
if o.selected and not o.disabled]
AttributeError: 'str' object has no attribute 'selected'

你知道问题出在哪里吗?我该如何解决?
非常感谢提前

你有我的代码:
import mechanize

br = mechanize.Browser()
br.set_handle_robots( False )

br.open('https://podio.com/webforms/15218117/1020239')
br.select_form(nr=0)

print '******************************************************'
print 'Print Form:'
print br.form
print '******************************************************'

br.find_control('fields[pre-requisites][]').items[0].selected=True
br.find_control('fields[pre-requisites][]').items[1].selected=True
br.find_control('fields[pre-requisites][]').items[2].selected=True
br.find_control('fields[pre-requisites][]').items[3].selected=True
br.find_control('fields[pre-requisites][]').items[4].selected=True
br.find_control('fields[pre-requisites][]').items[5].selected=True
br.find_control('fields[pre-requisites][]').items[6].selected=True
br['fields[dept-billing-number]']= '1234567890'
br['fields[first-name]']='TESTING'
br['fields[last-name]']='TESTING'
br.find_control('fields[email][][type]').value = ['other']
br['fields[email][][value]']='testing@testing.org'
br.find_control('fields[phone][][type]').value =['other']
br['fields[phone][][value]'] = '55555555555555'
br['fields[meeting-title]'] = 'TESTING'
br['fields[meeting-date][start_date]']='2016-12-07'
br['fields[meeting-date][start_utc]']='17:00:00'
br['fields[meeting-date][end_date]'] ='2016-12-10'
br['fields[meeting-date][end_utc]'] ='18:00:00'
br['fields[meeting-location]'] ='TESTING'
br['fields[purpose-goals]'] = 'TESTING'
br['fields[meeting-agenda]'] = 'TESTING'
br['fields[reference-material]'] = 'TESTING'
br.find_control('fields[design-needs]').items[0] ='1'
br.find_control('fields[media-requested][]').items[0].selected=True
br.find_control('fields[media-requested][]').items[1].selected=True
br.find_control('fields[media-requested][]').items[2].selected=True
br.find_control('fields[media-requested][]').items[3].selected=True
br.find_control('fields[media-requested][]').items[4].selected=True
br.find_control('fields[media-requested][]').items[5].selected=True
br.find_control('fields[media-requested][]').items[6].selected=True
br.find_control('fields[media-requested][]').items[7].selected=True
br.find_control('fields[media-requested][]').items[8].selected=True
br.find_control('fields[media-requested][]').items[9].selected=True
br.find_control('fields[media-requested][]').items[10].selected=True
br.find_control('fields[media-requested][]').items[11].selected=True
br.find_control('fields[media-requested][]').items[12].selected=True
br.find_control('fields[media-requested][]').items[13].selected=True
br.find_control('fields[media-requested][]').items[14].selected=True
br.find_control('fields[media-requested][]').items[15].selected=True
br.find_control('fields[media-requested][]').items[16].selected=True
br.find_control('fields[media-requested][]').items[17].selected=True
br['fields[media-and-design-details]'] ='TESTING'
br.find_control('fields[event-registration][]').items[0].selected=True
br.find_control('fields[event-registration][]').items[1].selected=True
br.find_control('fields[event-registration][]').items[2].selected=True
br.find_control('fields[event-registration][]').items[3].selected=True
br['fields[event-rsvp-if-needed]'] ='TESTING'
br['fields[activation-deactivation-dates][start_date]'] ='2016-12-17'
br['fields[activation-deactivation-dates][start_utc]'] ='18:00:00'
br['fields[activation-deactivation-dates][end_date]'] ='2016-12-24'
br['fields[activation-deactivation-dates][end_utc]'] ='18:00:00'
br['fields[earlybird-cut-off][start_date]'] ='2016-12-24'
br['fields[earlybird-cut-off][start_utc]'] ='15:00:00'
br.find_control('fields[regular-price][currency]').items[0] ='USD'

br['fields[regular-price][value]'] ='0.01'

br.find_control('fields[price-categories][]').items[0].selected=True='11'
br.find_control('fields[price-categories][]').items[1].selected=True='12'
br.find_control('fields[price-categories][]').items[2].selected=True='12'
br.find_control('fields[price-categories][]').items[3].selected=True='12'
br.find_control('fields[price-categories][]').items[4].selected=True='12'
br.find_control('fields[price-categories][]').items[5].selected=True='12'
br.find_control('fields[price-categories][]').items[6].selected=True='12'
br.find_control('fields[price-categories][]').items[7].selected=True='12'
br.find_control('fields[price-categories][]').items[8].selected=True='12'
br.find_control('fields[price-categories][]').items[9].selected=True='12'
br.find_control('fields[price-categories][]').items[10].selected=True='12'
br.find_control('fields[price-categories][]').items[11].selected=True='12'

br.find_control('fields[sold-at-door]').items[0] ='1'

br['fields[pricing-detail]'] ='TESTING'
br['fields[ticket-availability]'] ='100'
br['fields[ticket-restrictions]'] ='10'
br['fields[receipt-details]'] ='TESTING'
br['fields[web-links]']='TESTING'

br['fields[url-shortcut]'] ='http://testing.testing.org'

br.submit()

print br.response().read()

最佳答案

尝试这个:

response = br.submit()
print(response.read())

关于Python Mechanize : Traceback in br. submit(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40986462/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com