用 requests 请求时可以正常返回结果:
import requests
import json
headers = {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "zh-CN,zh;q=0.9",
"Connection": "keep-alive",
"Content-Length": "56",
"Content-Type": "application/json",
"Host": "
www.bw30.com",
"Origin": "
http://www.bw30.com",
"Referer": "
http://www.bw30.com/",
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36",
}
data = json.dumps({"channeltype": "shortvideo", "tid": 8, "index": 0, "size": 10})
a =
requests.post("
http://www.bw30.com/videoserver/RPCACBCABF433DB30A893DC6C5863E3102C?tid=7", data=data, headers=headers)
print(a.text)
同样的代码逻辑放到 pyspider 中则无法正常返回数据:
def on_start(self):
for tag, tid in {"美食": 7, "资讯": 8, "体育": 10, "亲子": 9, "微记录": 11}.items():
url = "
http://www.bw30.com/videoserver/RPCACBCABF433DB30A893DC6C5863E3102C?tid={}".format(tid)
headers = {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "zh-CN,zh;q=0.9",
"Connection": "keep-alive",
"Content-Length": "56",
"Content-Type": "application/json",
"Host": "
www.bw30.com",
"Origin": "
http://www.bw30.com",
"Referer": "
http://www.bw30.com/",
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36",
}
data = {"channeltype": "shortvideo", "tid": tid, "index": 0, "size": 10}
data = str(data)
self.crawl(url, callback=self.index_page,save={'column_name':tag},method="POST",data=data, headers=headers)
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
https://www.v2ex.com/t/562506
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.