python网页爬虫例子_Python网络爬虫 - 一个简单的爬虫例子

下面我们创建一个真正的爬虫例子

爬取我的博客园个人主页首页的推荐文章列表和地址

scrape_home_articles.py

from urllib.request importurlopenfrom bs4 importBeautifulSoupimportre

html= urlopen("http://www.cnblogs.com/davidgu")

bsObj= BeautifulSoup(html, "html.parser")for link in bsObj.find("div", {"id":"main_container"}).findAll("a", href=re.compile("^http://www.cnblogs.com/davidgu/p")):if 'href' in link.attrs and not('class' inlink.attrs):print(link.string)print(link.attrs['href'])print("--------------------------------------------------------------")

运行结果:

[置顶]解决adb server端口被占用的问题

http://www.cnblogs.com/davidgu/p/4515236.html

--------------------------------------------------------------

[置顶]解决Eclipse下不自动拷贝apk到模拟器问题( The connection to adb is down, and a sever

http://www.cnblogs.com/davidgu/p/4390661.html

--------------------------------------------------------------

常用的正则表达式一览

http://www.cnblogs.com/davidgu/p/4831357.html

--------------------------------------------------------------

C++ 11 - STL - 函数对象(Function Object) (上)

http://www.cnblogs.com/davidgu/p/4829097.html

--------------------------------------------------------------

...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值