回顾爬虫的时候的一些小TIPS

1

json.dumps的时候默认会用ascii

所以在写入文件的时候会需要用到的指令变为json.dumps(a,ensuer_ascii=False),这样将禁止转换为ascii

然后再写入的时候用f.write(b.encode())

2

xpath做解析的时候发请求头会产生问题,因为很多网站会根据不同的浏览器返回不同的DOM结构

所以很多的时候可以用一个相对老的版本的IE的user-agent

3

xpath   / . / .. // * @ [] | [] N/A ()
jsonpath $ @ .OR[] N/A .. * N/A [] [,] ?() () N/A

4

xpath helper :ctrl+shift+x

xpath善用//div[contains(@id , 'woshiqianbanbu_')]/ 模糊查询方式

5

如果不配置环境变量的时候,那么PhantomJS需要进行如下方法设置

driver = webdriver.PhantomJS(executable_path="./phantomjs") #括号中的内容就是路径,如果把phantomjs加入环境变量,那么括号内为空即可

selenium不支持phantomjs了?不清楚,反正有个警告,而且phantomjs不能自动关闭的问题还是问题

原文地址:https://www.cnblogs.com/lawliet-y/p/8324742.html