美奇科技 发表于 2015-4-19 06:53:46

Python 实现腾讯新闻抓取

思路:

1.抓取腾讯新闻列表页面: http://news.qq.com/
2.提取详细页面的url:http://news.qq.com/a/20120814/000070.htm
3.在详细页中提取新闻标题和内容
4.去除提取内容中的html标签,生成txt文档
代码:
  



1 #coding=utf-8
2 import sys
3 import urllib2
4 import re
5 import os
6
7 def extract_url(info):
8   rege="http://news.qq.com/a/\d{8}/\d{6}.htm"
9   re_url = re.findall(rege, info)
10   return re_url
11
12 def extract_sub_web_title(sub_web):
13   re_key = ".+"
14   title = re.findall(re_key,sub_web)
15   return title
16
17 def extract_sub_web_content(sub_web):
18   re_key = "
页: [1]
查看完整版本: Python 实现腾讯新闻抓取