为什么请求的对象被重定向?


抓取数据时,请求出现了302,为什么?

请求地址拷到浏览器地址栏中能正确显示,为什么在程序中request却返回302?

代码片段:


 def parse2(self,response):
  print '111'


 def parse(self, response):
  for循环:
    link='http://onlinelibrary.wiley.com/doi/10.1002/anie.20150xxxx/full'
    yield Request(link,callback=self.parse2)

调试:

python 请求 scrapy 网页爬虫

betlich 8 years, 5 months ago

作为一名node的前端,我很负责任的说:当浏览器接受到一个302重定向响应的时候,浏览器会去检查响应头里面有没有location字段,然后直接跳转去location。

对银发没辙啊! answered 8 years, 5 months ago

顾名思义,你所请求的网页被服务器重定向到别的地址去了,浏览器能打开是因为浏览器打开了被重定向到的新地址。如果PHP的curl的话有个设置允许重定向的值CURLOPT_FOLLOWLOCATION设为1,python爬网页这么强大应该更没问题。

l0T0l answered 8 years, 5 months ago

浏览器说不定也302了,只是帮你自动跳转了

302不是错误,收到302之后应该跟随获取跳转后的网址内容

莫慌丶抱紧我 answered 8 years, 5 months ago

Your Answer