我正在使用Mechanize查找並提交表單。代碼如下所示:Python //機械化//找不到表格
url = "THIS_IS_A_LINK"
br = mechanize.Browser()
br.set_handle_robots(False)
br.addheaders=[('User-agent','chrome')]
br.open(url)
htmltext = br.open(url).read()
print htmltext
br.select_form(name="genericsearch_param.fulltext")
br["q"] = "metal"
res = br.submit()
content = res.read()
with open("mechanize_results.html", "w") as f:
f.write(content)
的HTML看起來像這樣:
<form method="get" action="/WHAT_SO_EVER" accept-charset="utf-8" class="clearfix" style="display: inline;"><input type="hidden" name="session.sessionid" value="sdfosdfosdf3482374892hsdfanw9023qjh"><input type="hidden" name="global_data.designmode" value="xf"><div class="clearfix">
<div class="left"><label for="genericsearch_param.fulltext">Searchterm</label><input type="text" class="text" id="genericsearch_param.fulltext" name="genericsearch_param.fulltext" value=""></div> <div class="right"><label for="genericsearch_param.part_id">Searcharea</label><select id="genericsearch_param.part_id" name="genericsearch_param.part_id">
我不想硒的工作,因爲這將有許多瀏覽器打開和關閉的。爲什麼Mechanize找不到表格?
真棒,很高興你想出來:) –