zoukankan      html  css  js  c++  java
  • 使用python获取博客园作者的文章列表的超链接以及标题

    # -*- 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*	*
    *s*	*s*.*?

    * * *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)



    
       
    
  • 相关阅读:
    洛谷 P3366 【模板】最小生成树
    libfreenect
    openni2 和opencv读取数据
    kinect数据读取
    kinect for windows sdk
    caffe android lib
    Hlsl2glsl
    手势识别半自动标注结果视频
    CLM
    10位算法大师
  • 原文地址:https://www.cnblogs.com/jzssuanfa/p/6715723.html
Copyright © 2011-2022 走看看