最新消息:20210917 已从crifan.com换到crifan.org

【基本解决】PySpider打开页面出现304

页面 crifan 485浏览 0评论
折腾:
【暂时解决】给PySpider中用科学上网的代理打开需要翻墙的页面
期间,调试PySpider发现打开页面,出现很多错误,其中有304:
console: AT: [getOffer()] request failed [object Object]
console: AT: Rendering : failed target-global-mbox error timeout
[304] https://www.scholastic.com/teachers/bookwizard/ 20.146
[I 181010 15:46:44 tornado_fetcher:520] [304] ScholasticStorybook:34b1c45f09fa84805dd1697c1809e8c9 https://www.scholastic.com/teachers/bookwizard/ 20.15s
PySpider http 304
does “Force_update” and “itag” not work with HTTP status code 304? · Issue #573 · binux/pyspider
加上:
force_update=True,
试试,现象依旧:
[I 181010 16:02:23 tornado_fetcher:520] [304] ScholasticStorybook:34b1c45f09fa84805dd1697c1809e8c9 
https://www.scholastic.com/teachers/bookwizard/
 20.02s
关键还是不返回数据
does “Force_update” and “itag” not work with HTTP status code 304? · Issue #573 · binux/pyspider
试试:
crawl_config = {
  'force_update': True,
  'last_modified': False,
  'etag': False
}
问题依旧。
[译]理解HTTP/304响应 – 紫云飞 – 博客园
还是去官网详细了解这几个参数的含义:
http://docs.pyspider.org/en/latest/apis/self.crawl/#etag
“etag
use HTTP Etag mechanism to pass the process if the content of the page is not changed. default: True”
“last_modified
use HTTP Last-Modified header mechanism to pass the process if the content of the page is not changed. default: True”
“force_update
force update task params even if the task is in ACTIVE status.”
pyspider 304
Python urllib2.HTTPError: HTTP Error 304: Not Modified – 程序园
“I must create a new project like before to run it again, then the 304 problem is gone.
If you don’t want this feature, set etag and last_modified to False in self.crawl.”
结果此处虽然设置了:
    crawl_config = {
        "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36",
        # "proxy": "127.0.0.1:10870",
        # "proxy": "127.0.0.1:1087",
        # "proxy": "localhost:1087",

        'force_update': True,
        'last_modified': False,
        'etag': False
    }
但是结果竟然还是:
返回为空
然后不关闭页面,再次运行的话,就可以正常加载内容了:
再次运行又304
再去运行也还是304
怀疑可能是phantomjs的问题?
去停掉PySpider 重新开启:
看看是否一定可以200,而不是304
然后发现果然是的:
每次重启PySpider后,的确可以保证此处的:
https://www.scholastic.com/teachers/bookwizard/
(虽然内部部分js有错误)
但是页面可以正常加载,是200
-》看来就是phantomjs方面的问题?
-》或者说是和前面几个参数:
force_update,last_modified,etag
有关系。
所以此处是:
  • 每次重启PySpider的话,可以避免304
    • 但是后续在WebUI中调试,再次Run,还是会经常遇到304
    • 如果只是考虑到此处的需求:调试代码时,确保第一次运行不会304,后续正在开始运行时,就不会有问题
      • 则可以暂时不继续深究了
  • 但是为了想要搞清楚到底如何才能避免此问题,还是继续看看,能否彻底解决
pyspider如何处理重定向问题? – SegmentFault 思否
pyspider – 经常出现database is locked是怎么回事?rate/burst设置为1/1还是会有这个问题 – SegmentFault 思否
pyspider avoid 304
http – How to prevent request that returns 304 – Stack Overflow
没有完全看懂,大概意思是:Spec和Chrome,Firefox等不同浏览器,做法都不太一样
但是都是根据spec来的。
disable caching – How do I stop my rails application from returning a 304 – Stack Overflow
感觉此处有304,估计是用了fetch_type=”js”,导致js部分用了phantomjs
然后其内部估计用了缓存,导致此处的304?
【总结】
此处,在WebUI中调试时,对于:
https://www.scholastic.com/teachers/bookwizard/
最开始是200
之后再去Run,就是304了。
对此,暂时还是没有找到彻底的解决304的办法。
不过发现:重启PySpider,此处不会304
-》基本满足了此处调试和后续正式运行时,确保是200,算是暂时避免了304的问题。

转载请注明:在路上 » 【基本解决】PySpider打开页面出现304

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
90 queries in 0.177 seconds, using 23.41MB memory