网站首页 > 博客文章 正文
Beautiful Soup 是一个可以从HTML或XML文件中提取数据的Python库,它能够通过你喜欢的转换器实现惯用的文档导航,查找,修改文档的方式,Beautiful Soup会帮你节省数小时甚至数天的工作时间。
一、安装BeautifulSoup
cmd> pip install bs4
二、将html源码以lxml方式解析,得到一个"bs4.BeautifulSoup"对象
# -*- coding:utf-8 -*-
import requests
from bs4 import BeautifulSoup
def get_html():
url = r'https://www.baidu.com/'
headers = {'user-agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:57.0) Gecko/20100101 Firefox/57.0'}
res = requests.get(url=url, headers=headers, timeout=10).text
return res
html = get_html()
soup = BeautifulSoup(html, 'lxml')
print(type(soup))
运行结果:
<class 'bs4.BeautifulSoup'>
猜你喜欢
- 2024-09-27 蚂蚁SEO的网络蜘蛛如何应用(seo蜘蛛是什么意思)
- 2024-09-27 10《Python 原生爬虫教程》BeatifulSoup 的使用
- 2024-09-27 Python代码片段——第三方库自动安装
- 2024-09-27 「Github一周热点32期」本周最火的5个开源项目
- 2024-09-27 python爬虫CSS 选择器-BeautifulSoup4
- 2024-09-27 一篇文章搞定Python爬虫BeautifulSoup解析库
- 2024-09-27 Python学习——网络爬虫-下载小说
- 2024-09-27 python爬虫07 | 有了BeautifulSoup,妈妈不担心我的正则表达式
- 2024-09-27 使用 Python 的 Requests 和 BeautifulSoup 库爬取网站视频
- 2024-09-27 Python爬虫利器(1)Beautiful Soup
你 发表评论:
欢迎- 最近发表
-
- 给3D Slicer添加Python第三方插件库
- Python自动化——pytest常用插件详解
- Pycharm下安装MicroPython Tools插件(ESP32开发板)
- IntelliJ IDEA 2025.1.3 发布(idea 2020)
- IDEA+Continue插件+DeepSeek:开发者效率飙升的「三体组合」!
- Cursor:提升Python开发效率的必备IDE及插件安装指南
- 日本旅行时想借厕所、买香烟怎么办?便利商店里能解决大问题!
- 11天!日本史上最长黄金周来了!旅游万金句总结!
- 北川景子&DAIGO缘定1.11 召开记者会宣布结婚
- PIKO‘PPAP’ 洗脑歌登上美国告示牌
- 标签列表
-
- ifneq (61)
- messagesource (56)
- aspose.pdf破解版 (56)
- promise.race (63)
- 2019cad序列号和密钥激活码 (62)
- window.performance (66)
- qt删除文件夹 (72)
- mysqlcaching_sha2_password (64)
- ubuntu升级gcc (58)
- nacos启动失败 (64)
- ssh-add (70)
- jwt漏洞 (58)
- macos14下载 (58)
- yarnnode (62)
- abstractqueuedsynchronizer (64)
- source~/.bashrc没有那个文件或目录 (65)
- springboot整合activiti工作流 (70)
- jmeter插件下载 (61)
- 抓包分析 (60)
- idea创建mavenweb项目 (65)
- vue回到顶部 (57)
- qcombobox样式表 (68)
- vue数组concat (56)
- tomcatundertow (58)
- pastemac (61)
本文暂时没有评论,来添加一个吧(●'◡'●)