0
這裏是新手。Python/Mechanize不識別輸入表格
我正試圖將文本輸入到網站上的搜索框中。
出於某種原因,它似乎像搜索框不算作一種形式。
「形式」 是這樣的:
<th align="left" scope="col">
<input type="text" name="searchbox" id="searchboxid" size="40" class="search_box ac_input" autocomplete="off">
我收到此錯誤信息:
select_form
raise FormNotFoundError("no form matching "+description)
我的代碼:
import urllib
import urllib2
import cookielib
import requests
import mechanize
from mechanize._opener import urlopen
from mechanize._form import ParseResponse
browser = mechanize.Browser()
browser.open("theadress.com")
browser.select_form(nr=0)
browser.form["searchbox"] = "input"
browser.submit()
我也試圖尋找由表單使用browser.select_form[name="searchbox"]
但獲得相同的錯誤消息。
試圖列出形式得到什麼:這裏
for form in browser.forms():
print "Form name:", form.name
print form