我使用下面的代码来抓取网页“http://gs.amac.org.cn:10080/amac-infodisc/res/pof/manager/index.html”。为了浏览网页,我使用json格式发布数据。它可以响应json内容。奇怪的是它总是响应相同的内容,不管它是什么“页数”或什么“大小”是的。所以呢任何对此问题感兴趣的人都可以尝试更改“postdata”中的“page”编号,并查看相同的“id”响应。你知道吗
import urllib2
import urllib
import json
import random
headers = {"User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 UBrowser/5.6.10551.6 Safari/537.36",
"Content-Type": "application/json"}
# http://gs.amac.org.cn:10080/amac-infodisc/res/pof/manager/index.html
# change the "page" number here, response the same "id"
postdata = {"rand":random.random(),"page":10,"size":20}
url = "http://gs.amac.org.cn:10080/amac-infodisc/api/pof/manager"
postdata = json.dumps(postdata)
req = urllib2.Request(url,data=postdata,headers=headers)
response = json.load(urllib2.urlopen(req,timeout=30))
print response["content"][0]["id"]
问题是页面的参数不是作为post数据发送的,而是作为查询参数发送的:
更改参数类型可以解决此问题:
这将打印
101000000409
(101000000138
页0)。你知道吗相关问题 更多 >
编程相关推荐