再叙python

2016-11-17 0 条评论 384 次阅读 0 人点赞

之前看了好几遍的 python语法,这一阵忙完开始复习.import re import urllib.request from urllib.error import URLError,HTTPError import sys if name == 'main': url = "http://www.qiushibaike.com/imgrank/page/1" user_angent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)' headers = { 'Connection': 'Keep-Alive', 'Accept': 'text/html, application/xhtml+xml, /', 'Accept-Language': 'en-US,en;q=0.8,zh-Hans-CN;q=0.5,zh-Hans;q=0.3', 'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko' } j=0 for i in range(1,11+1): try: url = re.sub('page/\d+','page/%d' % i,url,re.S) print(url) re = urllib.request.Request(url,headers=headers) response = urllib.request.urlopen(re,timeout=10) items1 = re.findall('<div class="article block untagged mb15" id=(.*?)<div class="stats"', response.read().decode('utf-8'), re.S) print(items1) except HTTPError as e: print("eee")

TestSmirk

这个人太懒什么东西都没留下

文章评论(0)