您的位置:首页 > 编程语言 > Python开发

python urllib2实现刷博客

2016-08-31 18:46 288 查看
#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = 'MrChen'

import urllib2
import time

# 使用build_opener()是为了让python程序模仿浏览器进行访问
opener = urllib2.build_opener()
opener.addheaders = [('User-agent', 'Mozilla/5.0')]

# 专刷某个页面
print('开始刷了哦:')
tempUrl = 'http://blog.csdn.net/calling_wisdom/article/details/40900815'
for j in range(200):
try:
opener.open(tempUrl)
print('%d %s' % (j, tempUrl))
except urllib.error.HTTPError:
print('urllib.error.HTTPError')
time.sleep(1)
except urllib.error.URLError:
print('urllib.error.URLError')
time.sleep(1)
time.sleep(0.1)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: