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,但如果我想遵守,我就無能爲力了 –