发布时间:2019-07-23 09:41:52编辑:auto阅读(2017)
# coding:utf-8
# 引入相关模块
import json
import requests
from bs4 import BeautifulSoup
url = "http://news.qq.com/"
# 请求腾讯新闻的URL,获取其text文本
wbdata = requests.get(url).text
# 对获取到的文本进行解析
soup = BeautifulSoup(wbdata,'lxml')
# 从解析文件中通过select选择器定位指定的元素,返回一个列表
news_titles = soup.select("div.text > em.f14 > a.linkto")
#对返回的列表进行遍历
for n in news_titles:
# 提取出标题和链接信息
title = n.get_text()
link = n.get("href")
data = {
'标题':title,
'链接':link
}
print json.dumps(data).decode("unicode-escape").replace(u'\ufffd', u' ')
上一篇: Python学习-hashlib
下一篇: python单个接口测试记录
54316
41076
35590
31201
26084
25822
24285
19830
15877
15332
2152°
1982°
2077°
2178°
2166°
2351°
2300°
2110°
2180°
2164°