scrapy shell 爬取一些网站不响应

在爬去京东某商品网页时,如https://search.jd.com/Search?keyword=%E6%83%A0%E6%99%AE&enc=utf-8&suggest=1.his.0.0&wq=&pvid=d66c3ae3039d42b09f015585015ef653    实际上用   https://search.jd.com/Search?keyword=惠普&enc=utf-8  也可以

但是在scrapy shell 里始终无响应,仔细观察,你会发现有从定向的的现象,因此我们要解决的从定向问题(个人认为原因是出在这个地方)

在scrapy.Request中,我们知道可以通过设置参数来阻止重定向

from scrapy import Request
Request("https://search.jd.com/Search?keyword=惠普&enc=utf-8",meta = {'dont_redirect': True})

{

区分scrapy的Request对象

python 的第三方库 requests模块

pip install requests

import requests
html = requests.get(url, headers=headers, allow_redirects=False)

}

回来

那么如何在shell里实现

scrapy shell

from scrapy import Request

response=Request("https://search.jd.com/Search?keyword=惠普&enc=utf-8",meta = { 'dont_redirect': True})

re = fetch(response)




你可能感兴趣的:(python爬虫)