发布时间:2019-07-23 09:41:52编辑:auto阅读(1311)
# 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单个接口测试记录
48102
46789
37711
35037
29576
26237
25166
20203
19841
18315
5988°
6672°
6164°
6153°
7264°
6103°
6212°
6684°
6649°
8040°