让一个bot[python]将数据输入到websi中

2024-10-03 00:27:41 发布

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

我刚刚开始研究Python。在

站点:http://toolserver.org/~diberri/cgi-bin/html2wiki/index.cgi

机器人有没有可能把数据放在顶部的框中,或者勾选一个框或其他什么,然后点击底部的“转换”按钮?在

哦,还有,在选项标题下,有一个框,你可以选择各种选项。你到底是怎么让机器人选择其中一个的呢?在

谢谢


Tags: 数据orghttp标题indexbin站点选项
1条回答
网友
1楼 · 发布于 2024-10-03 00:27:41

当然你可以,但是你不会用你的机器人输入HTML代码。如果您查看页面的源代码,您将看到:

<form method="post" action="index.cgi">
<fieldset style="display:none">
  <input type="hidden" name="m" value="convert" />
</fieldset> 
...

它确实说明表单使用post方法传递到这个uri:http://toolserver.org/~diberri/cgi-bin/html2wiki/index.cgi

现在您可以看看urllib2,urllib2,这是http请求的python库。并使用所需参数创建post请求。在

例如:

^{pr2}$

您将需要一个标头,告诉服务器谁在执行请求:

例如:

headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}

像这样:

u = urllib2.urlopen(' http://toolserver.org/~diberri/cgi-bin/html2wiki/index.cgi', params)
h.request('POST', ' http://toolserver.org/~diberri/cgi-bin/html2wiki/index.cgi', params, headers)

相关问题 更多 >