首页 > 其他 > 详细

Beautifulsoup

时间:2020-05-17 22:56:54      阅读:83      评论:0      收藏:0      [点我收藏+]
Beautiful Soup:解析HTML页面信息标记与提取方法

 

获取网页源代码

import requests
from bs4 import BeautifulSoup

kv = {user-agent:Mozilla/5.0}
url = "https://python123.io/ws/demo.html"
r = requests.get(url,headers = kv)
print(r.status_code)
demo = r.text
soup = BeautifulSoup(demo,"html.parser")#解析
print(soup.prettify())

 

200
<html><head><title>This is a python demo page</title></head>
<body>
<p class="title"><b>The demo python introduces several python courses.</b></p>
<p class="course">Python is a wonderful general-purpose programming language. You can learn Python from novice to professional by tracking the following courses:
<a href="http://www.icourse163.org/course/BIT-268001" class="py1" id="link1">Basic Python</a> and <a href="http://www.icourse163.org/course/BIT-1001870001" class="py2" id="link2">Advanced Python</a>.</p>
</body></html>

 

 

 

<html>
<head>
<title>
This is a python demo page
</title>
</head>
<body>
<p class="title">
<b>
The demo python introduces several python courses.
</b>
</p>
<p class="course">
Python is a wonderful general-purpose programming language. You can learn Python from novice to professional by tracking the following courses:
<a class="py1" href="http://www.icourse163.org/course/BIT-268001" id="link1">
Basic Python
</a>
and
<a class="py2" href="http://www.icourse163.org/course/BIT-1001870001" id="link2">
Advanced Python
</a>
.
</p>
</body>
</html>

 

 

 

BeautifulSoup的使用

技术分享图片

 

Beautifulsoup

原文:https://www.cnblogs.com/tingtin/p/12907452.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!