1
我需要在提交搜索表单后在网站上执行某些操作。问题是,当我通过浏览器执行此操作时,页面不会重新加载,也不会重定向到任何位置:结果显示在搜索表单下方,不会对链接进行任何更改,但我可以在“新”页面中看到它们HTML。 但是当我使用下面的代码,我不能看到“新”的页面HTML应该是在响应(提供的链接是一个我其实是想用工作):Python3:通过MechanicalSoup提交表单时没有任何反应
import mechanicalsoup
def fetchfile(query):
url = "http://www.italgiure.giustizia.it/sncass/"
browser = mechanicalsoup.Browser()
page = browser.get(url)
search_form = page.soup.find("form", {"id": "z-form"})
search_form.find("input", {"id":"searchterm"})["value"] = query
response = browser.submit(search_form, page.url)
print(response) # the response is 200, so it should be a good sign
# actual parsing will come later...
print("1235" in response.text) # quick-check to see if there is what I'm looking for, but I get False
# in fact this...
print(page.text == response.text) # ...gives me True
fetchfile("1235/2012")
我可以不明白我错过了什么。我宁愿不使用硒。任何线索?
感谢您的回答,但最终我不得不使用硒,因为提交结果后,我需要下载PDF文件......,似乎没有其他方式比使用硒和“点击“那些结果。我的新问题是robots.txt,但如果我想遵守,我就无能为力了 –