1.首先在下面链接下载httplib2模块,解压到某一个文件夹下,来配置好py的环境和httplib。
2.配置好python的系统环境变量。
3.dos下安装httplib2模块,进入httplib2的解压目录下,运行 python setup.py install 安装即可。(Linux下安装使用easy_install httplib2)
D:\Python27\httplib2>setup.py install
running install
running bdist_egg
running egg_info
..........
Installed d:\python27\lib\site-packages\httplib2-0.9-py2.7.egg
Processing dependencies for httplib2==0.9
Finished processing dependencies for httplib2==0.9
安装成功~
爬虫案例:
打开一个网页的代码为:
webbrowser.open_new_tab('网址')
有于打开一定数量的网页后,内存会增加,我们需要定时关掉浏览器,关掉浏览器的代码如下(关掉Chrome为例):
os.system('taskkill /F /IM chrome.exe')
同时要使用到while循环来循环操作,达到刷博客的目的。具体的代码仿照了智普教育学习视频,感谢智普教育,完整的代码如下:
importwebbrowser as web
importtime
importos
importrandom
count = random.randint(5,7)
j=0
whilej<=count:
i=0
whilei<=8:
web.open_new_tab('http://www.mrliangqi.com/?p=138')#网址自己填入
i=i+1
time.sleep(0.8)
else:
os.system('taskkill /F /IM chrome.exe')
printj,'time webbrower closed'
j=j+1
最后把上面脚本保存为.py脚本执行即可!