使用python获取博客园作者的文章列表的超链接以及标题
2017-04-15 21:23
537 查看
# -*- coding: utf-8 -*- """ Created on Thu Jun 12 09:37:48 2014 @author: lifeix """ import re import urllib2 import cookielib url = 'http://www.cnblogs.com/wendingding/tag/IOS%E5%BC%80%E5%8F%91/default.html?page=' #url = 'http://www.cnblogs.com/smileEvday/category/578973.html?page=' reg = '<a id="\w+" href="http://www.cnblogs.com/\w+/p/\w+.html">\s*\t*\n*\s*\t*\s*.*?\t*\n*\t*\s*</a>' def startParse(author,page=1): cj = cookielib.LWPCookieJar() cookie_support = urllib2.HTTPCookieProcessor(cj) opener = urllib2.build_opener(cookie_support,urllib2.HTTPHandler) urllib2.install_opener(opener) headers = {'User-Agent' : 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20100101 Firefox/14.0.1', 'Referer' : "http://www.cnblogs.com"} flag = True while flag == True: nurl = url + str(page) req = urllib2.Request(nurl,headers=headers) resp = urllib2.urlopen(req) data = resp.read() regex = re.compile(reg,flags=re.MULTILINE) result = regex.findall(data) for d in result: print d if len(result) < 20: flag = False else: page = page + 1 print 'finished----------------------page:%d'%page if __name__ == '__main__': startParse('',1)
相关文章推荐
- 使用python获取博客园作者的文章列表的超链接以及标题
- PHPCMS使用get标签获取文章列表过滤重复标题并实现分页
- 使用HtmlUnit获取博客园第一页的所有文章标题
- 如何使用Hpple解析HTML,以及获取网站上的所有超链接
- 有关利用python获取网页, 以及KDD近几年论文标题与摘要链接
- 使用Python脚本获取指定格式文件列表的方法
- 我的第一次Python爬虫——获取自己博客园的所有文章
- 使用python的列表解析以及函数式计算来简化代码
- Python3.X登录模拟CSDN,获取文章列表
- 零基础学python-12.5 修改列表的误区以及使用for和range修改列表
- 使用Python自动获取可用代理列表
- python-77:获取最新文章的标题,网址
- Python动态加载模块以及模块类列表获取
- 网络采集软件核心技术剖析系列(1)---如何使用C#语言获取博客园某个博主的全部随笔链接及标题
- 零基础学python-12.5 修改列表的误区以及使用for和range修改列表
- 使用Python模拟登录QQ邮箱获取QQ好友列表
- 【python】获取51cto博客的文章列表
- 使用Python获取指定文件夹下文件名列表
- 网络采集软件核心技术剖析系列(1)---如何使用C#语言获取博客园某个博主的全部随笔链接及标题
- DTCMS自定义标签,获取所有栏目文章列表TOP,以及文章通用URL