如何在python中向web表单提交数据?

2024-04-26 13:05:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试自动创建一个帐户的过程,让我们称之为X,但我不知道该怎么做

我在什么地方看到了这个代码

import urllib
import urllib2
import webbrowser

data = urllib.urlencode({'q': 'Python'})
url = 'http://duckduckgo.com/html/'
full_url = url + '?' + data
response = urllib2.urlopen(full_url)
with open("results.html", "w") as f:
    f.write(response.read())

webbrowser.open("results.html")

但我不知道如何修改它以供我使用


Tags: 代码importurldata过程responsehtml地方
1条回答
网友
1楼 · 发布于 2024-04-26 13:05:21

我强烈建议您使用Selenium+Webdriver,因为您的问题是基于UI和浏览器的。在大多数情况下,您可以通过“pip install Selenium”安装Selenium。这里有几个很好的参考资料。 -http://selenium-python.readthedocs.io/ -https://pypi.python.org/pypi/selenium 另外,如果这个过程需要无头地驱动浏览器,请查看including PhantomJS(通过GhostDriver),可以从PhantomJS.org网站下载

相关问题 更多 >