How to avoid redirection of the webcrawler to the mobile edition?

时间秒杀一切 提交于 2020-01-05 12:17:23

问题


I subclassed a CrawlSpider and want to extract data from website. However, I always get redirected to the site's mobile version. I tried to change the USER_AGENT variable in scrapy's settings to Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1, but still get redirected.

Is there another way to signal another client and avoid redirection?


回答1:


There are two types of redirection supported in Scrapy:

  • RedirectMiddleware - Handle redirection of requests based on response status
  • MetaRefreshMiddleware - Handle redirection of requests based on meta-refresh html tag

So, maybe your html page uses second type of redirection?

See also:

  • http://doc.scrapy.org/en/latest/topics/downloader-middleware.html#redirectmiddleware-settings
  • http://doc.scrapy.org/en/latest/topics/downloader-middleware.html#metarefreshmiddleware-settings


来源:https://stackoverflow.com/questions/19047052/how-to-avoid-redirection-of-the-webcrawler-to-the-mobile-edition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!