- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章Python实战快速上手BeautifulSoup库爬取专栏标题和地址由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
BeautifulSoup库快速上手 。
。
pip install beautifulsoup4# 上面的安装失败使用下面的 使用镜像pip install beautifulsoup4 -i https://pypi.tuna.tsinghua.edu.cn/simple
使用PyCharm的命令行 。
。
from bs4 import BeautifulSoupimport requestsurl="https://blog.csdn.net/weixin_42403632/category_11076268.html"headers={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:93.0) Gecko/20100101 Firefox/93.0"}html=requests.get(url,headers=headers).texts=BeautifulSoup(html,"html.parser")title =s.select("h2")for i in title: print(i.text)
第一行代码:导入BeautifulSoup库 。
第二行代码:导入requests 。
第3、4、五行代码:获取url的html 。
第六行代码:激活BeautifulSoup库 "html.parser"设置解析器为HTML解析器 。
第七行代码:选取所有<h2>标签 。
。
BeautifulSoup库 支持根据特定属性解析网页元素 。
。
from bs4 import BeautifulSoupimport requestsurl="https://blog.csdn.net/weixin_42403632/category_11076268.html"headers={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:93.0) Gecko/20100101 Firefox/93.0"}html=requests.get(url,headers=headers).texts=BeautifulSoup(html,"html.parser")title =s.select(".column_article_title")for i in title: print(i.text)
。
from bs4 import BeautifulSouphtml="""<div class="crop-img-before"> <img src="" </div> <div id="title"> 测试成功 </div> <div class="crop-zoom"> <a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="bt-reduce">-</a><a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="bt-add">+</a> </div> <div class="crop-img-after"> <div class="final-img"></div> </div>"""s=BeautifulSoup(html,"html.parser")title =s.select("#title")for i in title: print(i.text)
。
from bs4 import BeautifulSouphtml="""<div class="crop-img-before"> <img src="" </div> <div id="title"> 456456465 <h1>测试成功</h1> </div> <div class="crop-zoom"> <a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="bt-reduce">-</a><a href="javascript:;" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="bt-add">+</a> </div> <div class="crop-img-after"> <div class="final-img"></div> </div>"""s=BeautifulSoup(html,"html.parser")title =s.select("#title")for i in title: print(i.text)title =s.select("#title h1")for i in title: print(i.text)
。
title =s.select("a")for i in title: print(i["href"])
。
from bs4 import BeautifulSoupimport requestsimport reurl="https://blog.csdn.net/weixin_42403632/category_11298953.html"headers={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:93.0) Gecko/20100101 Firefox/93.0"}html=requests.get(url,headers=headers).texts=BeautifulSoup(html,"html.parser")title =s.select(".column_article_list li a")for i in title: print((re.findall("原创.*?(.*?)",i.text))[0].lstrip()) print(i["href"])
到此这篇关于Python实战快速上手BeautifulSoup库爬取专栏标题和地址的文章就介绍到这了,更多相关Python BeautifulSoup库内容请搜索我以前的文章或继续浏览下面的相关文章希望大家以后多多支持我! 。
原文链接:https://blog.csdn.net/weixin_42403632/article/details/120852131 。
最后此篇关于Python实战快速上手BeautifulSoup库爬取专栏标题和地址的文章就讲到这里了,如果你想了解更多关于Python实战快速上手BeautifulSoup库爬取专栏标题和地址的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
实战-行业攻防应急响应 简介: 服务器场景操作系统 Ubuntu 服务器账号密码:root/security123 分析流量包在/home/security/security.pcap 相
背景 最近公司将我们之前使用的链路工具切换为了 OpenTelemetry. 我们的技术栈是: OTLP C
一 同一类的方法都用 synchronized 修饰 1 代码 package concurrent; import java.util.concurrent.TimeUnit; public c
一 简单例子 1 代码 package concurrent.threadlocal; /** * ThreadLocal测试 * * @author cakin */ public class T
1. 问题背景 问题发生在快递分拣的流程中,我尽可能将业务背景简化,让大家只关注并发问题本身。 分拣业务针对每个快递包裹都会生成一个任务,我们称它为 task。task 中有两个字段需要
实战环境 elastic search 8.5.0 + kibna 8.5.0 + springboot 3.0.2 + spring data elasticsearch 5.0.2 +
Win10下yolov8 tensorrt模型加速部署【实战】 TensorRT-Alpha 基于tensorrt+cuda c++实现模型end2end的gpu加速,支持win10、
yolov8 tensorrt模型加速部署【实战】 TensorRT-Alpha 基于tensorrt+cuda c++实现模型end2end的gpu加速,支持win10、linux,
目录如下: 为什么需要自定义授权类型? 前面介绍OAuth2.0的基础知识点时介绍过支持的4种授权类型,分别如下: 授权码模式 简化模式 客户端模式 密码模式
今天这篇文章介绍一下如何在修改密码、修改权限、注销等场景下使JWT失效。 文章的目录如下: 解决方案 JWT最大的一个优势在于它是无状态的,自身包含了认证鉴权所需要的所有信息,服务器端
前言 大家好,我是捡田螺的小男孩。(求个星标置顶) 我们日常做分页需求时,一般会用limit实现,但是当偏移量特别大的时候,查询效率就变得低下。本文将分四个方案,讨论如何优化MySQL百万数
前言 大家好,我是捡田螺的小男孩。 平时我们写代码呢,多数情况都是流水线式写代码,基本就可以实现业务逻辑了。如何在写代码中找到乐趣呢,我觉得,最好的方式就是:使用设计模式优化自己
我们先讲一些arm汇编的基础知识。(我们以armv7为例,最新iphone5s上的64位暂不讨论) 基础知识部分: 首先你介绍一下寄存器: r0-r3:用于函数参数及返回值的传递 r4-r6
一 同一类的静态方法都用 synchronized 修饰 1 代码 package concurrent; import java.util.concurrent.TimeUnit; public
DRF快速写五个接口,比你用手也快··· 实战-DRF快速写接口 开发环境 Python3.6 Pycharm专业版2021.2.3 Sqlite3 Django 2.2 djangorestfram
一 添加依赖 org.apache.thrift libthrift 0.11.0 二 编写 IDL 通过 IDL(.thrift 文件)定义数据结构、异常和接口等数据,供各种编程语言使用 nam
我正在阅读 Redis in action e-book关于semaphores的章节.这是使用redis实现信号量的python代码 def acquire_semaphore(conn, semn
自定义控件在WPF开发中是很常见的,有时候某些控件需要契合业务或者美化统一样式,这时候就需要对控件做出一些改造。 目录 按钮设置圆角
师父布置的任务,让我写一个服务练练手,搞清楚socket的原理和过程后跑了一个小demo,很有成就感,代码内容也比较清晰易懂,很有教育启发意义。 代码 ?
? 1 2
我是一名优秀的程序员,十分优秀!