#-*- coding=utf-8 -*-
import urllib2
import codecs
import re
csdn_url =
"http://blog.csdn.net/walegahaha"
blog_url = [
"http://blog.csdn.net/walegahaha/article/details/51945421"
,
"http://blog.csdn.net/walegahaha/article/details/51867904"
,
"http://blog.csdn.net/walegahaha/article/details/51603040"
,
"http://blog.csdn.net/walegahaha/article/details/50938260"
,
"http://blog.csdn.net/walegahaha/article/details/50884627"
,
"http://blog.csdn.net/walegahaha/article/details/50877906"
,
"http://blog.csdn.net/walegahaha/article/details/50868049"
,
"http://blog.csdn.net/walegahaha/article/details/50533424"
,
"http://blog.csdn.net/walegahaha/article/details/50504522"
,
"http://blog.csdn.net/walegahaha/article/details/50489053"
,
"http://blog.csdn.net/walegahaha/article/details/50471417"
,
"http://blog.csdn.net/walegahaha/article/details/50464531"
,
"http://blog.csdn.net/walegahaha/article/details/50452959"
,
"http://blog.csdn.net/walegahaha/article/details/50435986"
,
]
class
CSDN(object):
def __init__(self):
self.csdn_url = csdn_url
self.blog_url = blog_url
self.headers = {
'User-Agent'
:
'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6'
,}
def openCsdn(self):
req = urllib2.Request(self.csdn_url, headers = self.headers)
response = urllib2.urlopen(req)
thePage = response.read()
response.close()
pattern =
"访问:<span>(\d+)次</span>"
number =
''
.join(re.findall(pattern, thePage))
print
number
def openBlog(self):
for
i in range(len(self.blog_url)):
req = urllib2.Request(self.blog_url[i], headers = self.headers)
response = urllib2.urlopen(req)
response.close()
for
i in range(500):
print
i
csdn = CSDN()
csdn.openCsdn()
csdn.openBlog()
csdn.openCsdn()