Python2.7环境下,近期关于使用爬虫遇到的问题汇总。

1."A cookie associated with a resource at http://google.com/ was set with `SameSite=None` but without `Secure`. A future release of Chrome will only deliver cookies marked `SameSite=None` if they are also marked `Secure`. You can review cookies in developer tools under Application>Storage>Cookies and see more details at https://www.chromestatus.com/feature/5633521622188032."

这是因为selenium中设置了chrome_options.add_argument('--no-sandbox') ,如果不需要用到cookie则不用管。之所以设置这个模式是因为出现了,essage: unknown error: session deleted because of page crash from unknown error: cannot determine loading status。

当然引发这个问题的最根本原因是,我使用了多个线程进行爬虫的时候,可能由于网速还是其他的原因,导致了标签页的崩溃(在https://stackoverflow.com/questions/53902507/unknown-error-session-deleted-because-of-page-crash-from-unknown-error-cannot)发现的。

出现这个bug是由于我开了太多的线程(每一个线程都是独立的进行网页爬虫(使用selenium)),导致了共享内存不够。

2.多线程中使用python自带的logging模块,会roating这个日志模块,会导致写入同一个日志(此时文件差不多已经满了),然后程序要进行修改当前文件名,然而已经被占用了。

解决方法:https://github.com/Preston-Landers/concurrent-log-handler,该大佬对roating这个翻滚模块进行了重写,别使用其他csdn博客的方法,他们进行的重写方法根本就没有用

3.对类中的某个方法对象为 ip=X(某类).XX(某方法不加括号,不用加参数,等调用再加)

你可能感兴趣的:(爬虫库知识)