发布时间:2019-07-23 09:41:52编辑:auto阅读(1985)
# 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单个接口测试记录
54067
40829
35338
31002
25895
25631
24067
19595
15671
15152
1874°
1726°
1819°
1890°
1892°
2059°
2018°
1849°
1937°
1919°