Python抓取新闻标题和链接
来源:互联网 发布:win2008 80端口被占用 编辑:程序博客网 时间:2024/04/28 13:16
#-*-coding:utf-8-*-
import re
from urllib import urlretrieve
from urllib import urlopen
#获取网页信息
doc = urlopen("http://www.itongji.cn/news/").read() #自己找的一个大数据的新闻网站
#抓取新闻标题和链接
def extract_title(info):
pat = '<h3><a target=\"_blank\"(.*?)</a></h3>'
title = re.findall(pat, info)
titles='\n'.join(title)
#print titles
#修改指定字符串
titles1=titles.replace('class="title"','title')
titles2=titles1.replace('>',':')
titles3=titles2.replace('href','url:')
titles4=titles3.replace('="/','"http://www.itongji.cn/')
save.close()
titles = extract_title(doc)
import re
from urllib import urlretrieve
from urllib import urlopen
#获取网页信息
doc = urlopen("http://www.itongji.cn/news/").read() #自己找的一个大数据的新闻网站
#抓取新闻标题和链接
def extract_title(info):
pat = '<h3><a target=\"_blank\"(.*?)</a></h3>'
title = re.findall(pat, info)
titles='\n'.join(title)
#print titles
#修改指定字符串
titles1=titles.replace('class="title"','title')
titles2=titles1.replace('>',':')
titles3=titles2.replace('href','url:')
titles4=titles3.replace('="/','"http://www.itongji.cn/')
#写入文件
save=open('xinwen.txt','w')
save.write(titles4)save.close()
titles = extract_title(doc)
1 0
- Python抓取新闻标题和链接
- Python利用Beautiful Soup抓取新闻标题
- 关于python网络爬虫——摘取新闻标题及链接
- Python抓取网页链接
- Python抓取网页链接
- Python抓取网页中的链接
- Python 抓取google链接代码
- Axure RP 新闻标题链接制作
- python爬去网页新闻标题
- Python抓取网页链接,存入mysql
- python抓取google链接原理详解
- Python抓取页面上的链接
- python抓取网页中的链接地址
- python - 抓取页面上的链接
- python爬虫抓取目标网页链接
- 转载:python使用urllib2抓取防爬取链接
- python使用urllib2抓取防爬取链接
- 打字效果的带链接的新闻标题
- 各种LG的5.0.1的root方法(VS985 24B亲测通过)
- 绝逼实用又美观的指南针应用(App)
- Tutorial #Facebook Relay文档翻译#
- TesterHome android app 编写历程(一)
- 读取网络中的数据并写入数据库
- Python抓取新闻标题和链接
- iOS 开发中实现打电话功能实用代码
- iOS大典之点击旋转, 点击停止
- 黑马程序员----C 语言学习笔记之位运算符
- Android之PullToRefresh(ListView 、GridView 、WebView)使用详解和总结
- 知识复习(LDT+TSS+GATE+INTERRUPT)
- 在Eclipse中添加Servlet-api.jar的方法
- Ubuntu虚拟机使用NAT方式连接(有线网、无线网测试均可用)
- Apache或者nginx反向代理时,request.getservername()出现的问题!