我打算使用 twill 在一页上填写表单,点击提交按钮,然后使用 BeautifulSoup 解析生成的页面。如何向 BeautifulSoup 提供 HTML 页面?我假设我必须阅读当前的网址,但我不知道如何实际返回网址才能这样做。我试过 twill 的 TwillBrowser.get_url(),但它只返回 None。
最佳答案
对于任何 future 的患者,我发现使用 mechanize 而不是 twill 的运气更好,因为 twill 是用于 mechanize 的未更新的薄外壳。解决方法如下:
import mechanize
url = "foo.com"
br = mechanize.Browser()
br.open(url)
br.select_form(name = "YOURFORMNAMEHERE") #make sure to leave the quotation marks
br["YOURINPUTFIELDNAMEHERE"] = ["YOURVALUEHERE"] #this must be in a list even if it is only one value
response = br.submit()
print response.geturl()
关于python - 如何使用 twill 查看当前 url?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9676110/