python - 如何使用 twill 查看当前 url?

标签 python twill

我打算使用 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/

相关文章:

python - 奇怪的 MySQL Python mod_wsgi Can't connect to MySQL server on 'localhost' (49) 问题

python - 从特定文本行读取文件

python - 网站提交按钮本地化时使用 Twill 的提交功能(Python)

python - 如何配置Python Twill/Mechanize库来访问Facebook

python - twill - 在运行时更改代理服务器设置

python - 如何使用已安装的 twill 登录网站?

Python Xls 编写器 : Is there any way to write 1400 columns in excel file?

python - 如何用Pygame画一个棋盘并移动棋盘上的棋子?

python - 如何让两个已发布的装置相互依赖?

python - 斜纹/机械化访问 html 内容