python抓取oschina最新文章
来源:互联网 发布:智博海天软件工程学院 编辑:程序博客网 时间:2024/05/31 18:53
# -*- coding:utf-8 -*- import urllib,urllib2 import os,Queue,random,sys from urllib import FancyURLopenerclass MyOpener(FancyURLopener): version='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/534.55.3 (KHTML, like Gecko) Version/5.1.3 Safari/534.53.10'class Spider: def get_html(self,url): myopener = MyOpener() sock = myopener.open(url) htmlSource = sock.read() sock.close() return htmlSource def analysis_html(self,htmlSource): import lxml.html.soupparser as soupparser dom = soupparser.fromstring(htmlSource) Url=dom.xpath('//*[@id="RecentBlogs"]/ul[1]/li/div/h3/a[@href]') title=dom.xpath('//*[@id="RecentBlogs"]/ul[1]/li/div/h3/a/text()') writer=dom.xpath('//*[@id="RecentBlogs"]/ul[1]/li/div/div/text()') for i in range(len(title)): print title[i].encode('utf-8'),Url[i].get('href').encode('utf-8'),writer[i].encode('utf-8')if __name__ == '__main__': spider = Spider() url=['http://www.oschina.net/blog/more?p=%s#' %(i) for i in range(10)] urls=Queue.Queue() for i in url: urls.put(i) for i in range(urls.qsize()): url=urls.get() htmlSource = spider.get_html(url) spider.analysis_html(htmlSource)
智普教育整理发布哦 www.jeapedu.com
- python抓取oschina最新文章
- python爬虫CSDN文章抓取
- Python 抓取文章网url及其文章
- python抓取QQ空间博客文章
- python抓取csdn博客文章信息
- Python 模拟登录和抓取文章
- Python爬虫抓取最新段子发送到指定邮箱
- 抓取文章
- python 自动登陆oschina
- 最新文章
- 最新文章
- 最新文章
- 最新文章
- 最新文章
- 最新文章
- 最新文章
- python爬虫之python2.7.8抓取csdn博客文章
- Python实现抓取CSDN博客首页文章列表
- 3月21日整理
- Python正则表达式的用法(1. 匹配)
- 激活 visio Premium 2010 vol 版本
- VC++动态链接库(DLL)编程深入浅出(1)
- 业务逻辑层,表示层,会话层及层间关系
- python抓取oschina最新文章
- 点击UpdatePanel中的按钮弹出javascript对话框
- Sublime Text 3 破解版 + 注册机 + 汉化包
- #program用法1
- Oracle 11g中Shrink Database Segment Online
- MFC - 进程间传递消息命令
- Spring中的设计模式
- VC++动态链接库(DLL)编程深入浅出(2)
- 在自己电脑上搭建服务器 发布自己的网站