Chinaunix首页 | 论坛 | 博客
  • 博客访问: 108897
  • 博文数量: 49
  • 博客积分: 2612
  • 博客等级: 少校
  • 技术积分: 431
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-01 14:31
个人简介

来来去去

文章分类

全部博文(49)

文章存档

2015年(1)

2012年(4)

2011年(1)

2010年(42)

2009年(1)

我的朋友

分类: Python/Ruby

2010-01-24 22:27:16

该程序通过获取页面的源码,从源码中读取数字来组成下一个链接的URL。


import os
import sys
import urllib
import re

def getsrc(url):
    src=urllib.urlopen(url).read() # Get the page source of the page.
    num=re.search('[\d]\d+',src) # search the digit from the page source.
    if not num: # if cant find digits from the page source,
        print src #then print the source and return the Excepion.
        return num.group(1)
    else:
        return num.group(0) # Return the digits.

if __name__=='__main__':
    url=''
    for n in range(400):
        print n
        num=getsrc(url)
        url=''+str(num) # use the return value(num) to create the next url.
    print num


阅读(454) | 评论(0) | 转发(0) |
0

上一篇:re.findall---find letters

下一篇:Pickle 序列化

给主人留下些什么吧!~~