a530317920
a530317920
2015-04-02 07:19
采纳率: 75%
浏览 2.2k

python 抓取POST 网页失败,求大神帮忙看下代码哪里有问题

![图片说明](https://img-ask.csdn.net/upload/201504/02/1427958956_940687.png)图片说明

这是网站请求的是Request Header 和携带的参数

import urllib
import urllib2

def GetFormDate( pageNum , catId ):
retValue = {}
retValue["module"] = "product"
retValue["from"] = "category"
retValue["page"] = "%d" % pageNum
paramJson = {"mobile" : False , "catalog" : "coo8Store" , "siteId" : "coo8Site" , "shopId" : "" , "regionId" : "31010100" , "pageName" : "list" , "et" : "" , "XSearch" : False , "startDate" : 0 , "endDate" : 0 , "pageSize" : 48 , "state" : 4 , "weight" : 0 , "more" : 0 , "sale" : 0 , "instock" : 1 , "filterReqFacets" : None , "rewriteTag" : False , "userId" : "" , "priceTag" : 0}
paramJson["catId"] = catId

retValue["paramJson"] = paramJson

return retValue

body=urllib.urlencode(GetFormDate(2,"cat15965738"))

request = urllib2.Request("http://www.gome.com.cn/p/asynSearch" )
request.add_header("Referer", "http://www.gome.com.cn/category/cat15965738.html")
request.add_header('Content-Type','application/json')
request.add_header('X-Requested-With','XMLHttpRequest')
request.add_header('HOST','www.gome.com.cn')
request.add_header('Accept-Language','zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3')
request.add_header('Accept','application/json, text/javascript, /; q=0.01')
f = urllib2.urlopen(request , json.dumps(GetFormDate(2,"cat15965738")))

content = f.read()
print content

这样写的话,获得的Content 一直是空,有哪位大神知道为什么吗,求解啊

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • oyljerry
    oyljerry 2015-04-02 07:35
    已采纳

    两个格式是否完全一致?自己仔细对比一下

    点赞 评论
  • a530317920
    a530317920 2015-04-02 07:22

    图片说明

    点赞 评论
  • a530317920
    a530317920 2015-04-02 07:26

    上面是在Chrome 上看到点击时候的信息,求大神来看看,帮助解决问题

    点赞 评论

相关推荐