我正在尝试使用python上的mechanize填充表单。当我运行代码时,我收到一个错误:
错误403:robots.txt禁止请求。
我按照类似问题查看了之前已回答的问题,并看到添加br.set_handle_robots(False)
应该修复它,但我仍然遇到同样的错误。那我在这里错过了什么?
import re
import mechanize
from mechanize import Browser
br = mechanize.Browser()
br.set_handle_equiv(False)
br.set_handle_robots(False)
br.addheaders = [('User-agent','Mozilla/5.0 (X11; Linux x86_64; rv:18.0)Gecko/20100101 Firefox/18.0 (compatible;)'),('Accept', '*/*')]
text = "1500103233"
browser = Browser()
browser.open("http://kuhs.ac.in/results.htm")
browser.select_form(nr=0)
browser['Stream']=['Medical']
browser['Level']=['UG']
browser['Course']=['MBBS']
browser['Scheme']=['MBBS 2015 Admissions']
browser['Year']=['Ist Year MBBS']
browser['Examination']=['First Professional MBBS Degree Regular(2015 Admissions) Examinations,August2016']
browser['Reg No']=text
response = browser.submit()
答案 0 :(得分:2)
False
然后设置br = mechanize.Browser()
?browser = Browser()
如果您可以从页面来源看到,则来源为:http://kuhs.ac.in/results.htm
src="http://14.139.185.148/kms/index.php/results/create"
为Stream</label
所以,你可以试试这个:
name="Results[streamId]"
您可以在此处看到:Submitting a form with mechanize (TypeError: ListControl, must set a sequence)
希望这有帮助,它对我有用!