一个Python 爬虫程序

来源:互联网 发布:金九银十的数据 编辑:程序博客网 时间:2024/05/18 03:17

一个简单的实现煎蛋网妹子图片爬取的Python脚本

# -*- coding:utf-8 -*-'''version:Python 2.6standard libs: urllibauthor:Dead_morningsystem: cetos 6.5'''import reimport urllibdef get_content(html_page):'''html downladd'''    html = urllib.urlopen(html_page)    content = html.read()    html.close()    return contentdef get_images(info):'''html parser'''    regex = r'href="//wx(.+?\.(?:gif|jpg|jpeg|png))" ' # download original picture    #使用正则表达式为了下载原图,这里可使用 soupbeautiful 模块替代正则表达式    pat = re.compile(regex)    image_code = map(lambda x: 'http://wx'+ x , re.findall(pat,info))    return image_codedef Download_image():''' image download'''    for image_url in get_images(info):        print image_url        image_name = image_url.split('/')[-1]        # 给文件命名         urllib.urlretrieve(image_url,image_name)def html_pages():''' URl list'''#因为煎蛋网的网址比较有规律,所以就用了一个简单的List替代了从网页里解析    b = []    for a in range (1 ,95):        url= 'http://jandan.net/ooxx/page-%s#comments' %a        b.append(url)    return bif __name__ == '__main__':       for html_page in html_pages():        info = get_content(html_page)        print Download_image()
原创粉丝点击