Python网络爬虫实例

news/2024/7/19 8:44:05 标签: python, 爬虫

视频地址:

http://edu.51cto.com/lesson/id-12393.html

 

下载博客文章实例

源码:

import urllib
import time

#下载博客所有文章
i = 0
url = ['']*50
con = urllib.urlopen('http://blog.sina.com.cn/s/articlelist_3973495073_0_1.html').read()
title = con.find(r'<a title=')
href = con.find(r'href=', title)
html = con.find(r'.html', href)

while title != -1 and href != -1 and html != -1 and i < 50:
    url[i] = con[href + 6:html + 5]
    print url[i]
    title = con.find(r'<a title=', html)
    href = con.find(r'href=', title)
    html = con.find(r'.html', href)
    i = i + 1
else:
    print 'find end!'

j = 0
while j < 50:
    content = urllib.urlopen(url[j]).read()
    open(r'hanhan/'+url[j][-26:],'w+').write(content)
    print 'downloading', url[j]
    j = j + 1
    time.sleep(1)
else:
    print 'download articles finished!'
    

 


http://www.niftyadmin.cn/n/1199755.html

相关文章

profile bashrc bash_profile 之间的区别和联系

原文链接&#xff1a;http://blog.sina.com.cn/s/blog_4b065e2a01013dp3.html /etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行.并从/etc/profile.d目录的配置文件中搜集shell的设置./etc/bashrc:为每一个运行bash shell的用户执行此文件.当…

float f = 3.4报错问题

Java中为何 float f 3.4会报错 Java中出现一个小数时&#xff0c;如果没有明确指出类型&#xff0c;那么默认是double类型的&#xff0c;所以在编译时&#xff0c;3.4为double类型的赋给float类型的f变量&#xff0c;为向下转型&#xff0c;会丢失精度所以报错。 怎么解决 …

xmemcached作者Dennis采访(转)

xmemcached是最近频繁出现在JavaEye新闻频道的热点词汇&#xff0c;它就是JavaEye的资深会员Dennis开发的基于java nio实现的高性能可扩展的memcached客户端。 Dennis 在自己实现的一个nio框架 http://code.google.com/p/yanf4j/ 的基础上实现了xmemcached项目(目前1.1.3是基于…

What Powers Instagram: Hundreds of Instances, Dozens of Technologies

What Powers Instagram: Hundreds of Instances, Dozens of Technologies One of the questions we always get asked at meet-ups and conversations with other engineers is, “what’s your stack?” We thought it would be fun to give a sense of all the systems that…

Hibernate5.3基础配置,创建SessionFactory和关联映射的注解

注&#xff1a;引入注解时&#xff0c;Entity等为javax.persistence包。Cascade和CascadeType为org.hibernate.annotations包.这里用的为Hibernate5.3 与之前创建SessionFactory有些不一样&#xff0c;在文章后面附上代码。 双向多对一 ‘多’的一方表 book&#xff0c;‘一’…

Windows 2003 安装 php5.3.2,用eclipse开发php

下载php,fastcgi 下载php5.3.2http://windows.php.net/download/下载 FastCGI for IIShttp://www.iis.net/download/fastcgi解压缩并配置php 解压缩php5.3.2到F:\soft_dev\php配置php.ini&#xff08;开发环境&#xff09;&#xff1a;将php.ini-development更名为php.ini后修改…

Hibernate HQL根据中文字段排序(order by)错乱的问题(MySQL数据库)

问题&#xff1a;HQL查询数据库根据中文字段排序时&#xff0c;发生错乱。 原因&#xff1a;网上查了一下原因&#xff0c;说是因为数据库的字符集是utf-8&#xff0c;UTF8 默认校对集是 utf8_general_ci , 它不是按照中文来的。你需要强制让MySQL按中文来排序。MySQL中使用 C…

xmemcached对权重的支持

在JavaMemCached这个memacched客户端&#xff0c;如果你有多个memcachd节点&#xff0c;你可以设置memcached server的权重&#xff0c;权重高的节点在存储、获取等操作就相应占的比重比较大。恰巧我最近也在实现一个类似这样流控的东西&#xff0c;因此在xmemcached实现了此fe…