编程爱好者之家
编程爱好者之家为大家带来python删除网页中含有lazy.png字符串的img标签并返回删除后的字符串
原始网页代码部分例子如下
<div> <noscript><img fetchpriority="high" decoding="async" class="alignnone size-full wp-image-3072" src="http://www.test.com/test.jpg" alt="20240709172357407" width="720" height="537" /></noscript> <img fetchpriority="high" decoding="async" class="alignnone size-full wp-image-3072 j-lazy" src="http://www.test.com/images/lazy.png" data-original="http://www.test.com/test.jpg" alt="20240709172357407" width="720" height="537" /> <img fetchpriority="high" decoding="async" class="alignnone size-full wp-image-3072 j-lazy" src="http://www.test.com/images/lazy.png" data-original="http://www.test.com/test2.jpg" alt="20240709172357407" width="720" height="537" /> </div>
实现代码如下:
from bs4 import BeautifulSoup resp = requests.get(url) #url为网页地址 soup = BeautifulSoup(resp.content, "html.parser") imgs = soup.find_all("img", src=re.compile(r".*lazy\.png")) for img in imgs: img.decompose()
windows11安装Java8(jdk1.8)详细教程
python采集B站某个用户的发表图文数据列表以及详情页数据到数据库代码
python字符串requests获取数据怎么转换为字典
python采集微博某个用户的发表数据列表以及详情页数据到数据库
python获取当前时间三个小时之后的随机时间戳
windows系统在cmd中执行 pip install numpy没反应解决办法
linux系统安装python 3.12.0教程
linux安装好python3后使用python命令提示-bash: python: command not found
ImportError: Can't connect to HTTPS URL because the SSL module is not available.
python删除网页中含有lazy.png字符串的img标签并返回删除后的字符串