我正在研究 Mechanize 以获取表单元素
import mechanize
br = mechanize.Browser()
br.set_handle_robots(False)
br.open("http://www.bnm.gov.my/index.php?ch=12&pg=622")
br.select_form(name="Rates")
但这是抛出错误:
FormNotFoundError: no form matching name 'Rates'
虽然有
<form onsubmit="return validate();" method="get" action="index.php" name="Rates">
有人可以帮忙吗
提前致谢
最佳答案
尝试使用 nr 参数选择表单:
select_form(self, name=None, predicate=None, nr=None)
我猜那个页面只有 1 个表单,所以试试 nr=0。
如果页面中没有表单,则可能意味着它是使用 Javascript 添加的。而且,在那种情况下, Mechanize 是不够的。您将不得不使用 Selenium 或 Spynner。
关于python Mechanize FormNotFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10426340/