我正在尝试在 Dell Kace 票务页面上选择一个表单,但出现解析错误。我正在用python编程并且一直在使用mechanize。我成功地能够登录到该站点。我读到您可能可以使用诸如 Beautiful soup 之类的 html 清洁器来解决此问题,但这些似乎都不起作用。
br = mechanize.Browser() #have tried the various html cleaner options in mechanize
cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)
br.set_handle_equiv(True)
br.set_handle_redirect(True)
br.set_handle_referer(True)
br.set_handle_robots(False)
br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US;
rv:1.9.0.1)Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')]
....
url_ticket = 'http://kace-server/adminui/ticket.php?ID=%d' %(box1[sel+1])
url_org1 = "http://kace-server/common/switch_to_org.php?org=1"
br.open(url_org1)
br.open(url_ticket)
br.select_form(name="ticket_form")
br.form['fields[owner_filter]']=current_user[0]
br.submit()
该程序在 br.select_form 行失败并出现以下错误
line 39, in assign
br.select_form(name="ticket_form")
....
File "C:\Python27\lib\site-packages\mechanize-0.2.5-py2.7.egg\mechanize\_form.py",
line 760, in feed raise ParseError(exc)
ParseError: expected name token at '<!\xe2\x80\x94IE7 mode --\n <'
我在 html 中搜索了那个 '!\xe2... 字符串,但找不到它。我还为 select_form 尝试了 nr=0。任何帮助将不胜感激
谢谢,詹姆斯