Python爬虫如何解析HTML页面,下面web建站小编给大家简单介绍一下!
具体语法如下:
import re
html = '''
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>这是页面标题</title>
</head>
<body>
<div class="content">
<h2>这是一级标题</h2>
<p>这是一段文本</p>
</div>
<div class="footer">
<p>版权所有 © 2021</p>
</div>
</body>
</html>
'''
pattern = re.compile(r'<div class="content">.*?<h2>(.*?)</h2>.*?<p>(.*?)</p>.*?</div>', re.S)
match = re.search(pattern, html)
if match:
title = match.group(1)
text = match.group(2)
print(title)
print(text)
上面是“Python爬虫如何解析HTML页面”的全面内容,想了解更多关于 前端知识 内容,请继续关注web建站教程。
当前网址:https://ipkd.cn/webs_4768.html
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

seo新手应该怎么学习(图文)
网站偶尔打不开(404页面)会影响网站权重吗
百度echarts利用南丁格尔图做一个上班摸鱼时间分布图
ComfyUI-OpenClaw安装使用步骤,安全优先为核心设计的ComfyUI自定义节点包 













