使用python抓取CSDN关注人的所有发布的文章

# -*- coding: utf-8 -*-
"""
@author: jiangfuqiang
"""
import re
import urllib2
import cookielib
import time

def startParser(author,page=1):
    reg = r'<a href="/\w+/article/details/\d+">\s*\t*\n*\s*\t*\s*.*?\t*\n*\t*\s*</a>'
    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://my.csdn.net/my/favorite'}
    flag = True
    while flag == True:
        time.sleep(2)
        url = "http://blog.csdn.net/%s/article/list/%d"%(author,page)
        req = urllib2.Request(url,headers=headers)
        resp = urllib2.urlopen(req)
        data = resp.read()
        regex = re.compile(reg,flags=re.MULTILINE)
        result = regex.findall(data)

        for rd in result:
            print rd
        if len(result) < 20:
            flag = False
        page = page + 1
    print 'success............page:%d'%page
    #print result.group()

if __name__ == '__main__':

    startParser('yiyaaixuexi',1)
这篇 python抓取收藏的文章链接和标题中有python发送邮件的代码,可以将此程序稍微改动之后将文章链接发送的邮箱以便以后查阅

 

                
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值