首页 > 如何用python访问网页并在表单处输入内容?

如何用python访问网页并在表单处输入内容?

我要用python在 http://tool.seowhy.com/keywords/ 这个网页输入{关键词:网址}并提交请求,请问如何实现?


试了一下{demo:demo.com},发现提交请求后访问了http://tool.seowhy.com/keywords/ajax?query=demo.com&time=1370231897&inajax=true, 如图:

其中time值在每次访问http://tool.seowhy.com/keywords/的时候得到,如下图(重新访问了seowhy,因此time值不同于前图):

提交post请求时还有带上keyword、searchengine的值.

总结下:你要做的是先抓取http://tool.seowhy.com/keywords/,分析取出time值,然后访问http://tool.seowhy.com/keywords/ajax?query=demo.com&time=1370231897&inajax=true, 其中的query替换为自己要查询的域名,time替换为上一步分析出来的值。post数据中keyword为关键词。

抓取网页可以用requests或者自带的urllib等库,分析网页可以用BeautifulSoup或者正则表达式.

【热门文章】
【热门文章】