没有合适的资源?快使用搜索试试~ 我知道了~
python爬虫代码(requests、BeautifulSoup).docx
需积分: 10 1 下载量 55 浏览量
2023-02-02
11:33:04
上传
评论
收藏 17KB DOCX 举报
温馨提示
试读
2页
requests+lxml/etree+xpath表达式 requests+BeautifulSoup+find_all进行信息提取
资源推荐
资源详情
资源评论
python 爬虫代码
方式一:
requests+lxml/etree+xpath 表达式
# lxml/etree method
import requests
from lxml import etree
headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0;
Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/64.0.3282.119 Safari/537.36'}
url = 'http://news.qq.com/'
html = requests.get(url = url, headers = headers)
con = etree.HTML(html.text)
title = con.xpath('//em[@class="f14 l24"]/a/text()')
link = con.xpath('//em[@class="f14 l24"]/a/@href')
for i in zip(title, link):
print({' 标 题 ': i[0],
'链接': i[1]
})
方式二:
requests+BeautifulSoup+find_all 进行信息提取
# find_all method
import requests
from bs4 import BeautifulSoup
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64;
x64) AppleWebKit/537.36 (KHTML, like Gecko)
Chrome/64.0.3282.119 Safari/537.36'}
url = 'http://news.qq.com/'
资源评论
海澜明月
- 粉丝: 23
- 资源: 2890
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功