楼主: shadowaver
1175 0

[程序分享] 爬虫的铺垫——网页HTML树状结构解析利器BeautifulSoup [推广有奖]

随心所欲不逾矩

已卖:1243份资源

教授

56%

还不是VIP/贵宾

-

威望
0
论坛币
8309 个
通用积分
689.8825
学术水平
18 点
热心指数
22 点
信用等级
13 点
经验
29709 点
帖子
890
精华
0
在线时间
1366 小时
注册时间
2007-9-27
最后登录
2025-12-31

楼主
shadowaver 在职认证  发表于 2021-12-27 14:26:06 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Dec 27 13:52:57 2021

@author: apache
"""

from bs4 import BeautifulSoup



html = """
<html><head><title>The Dormouse's story</title></head>
<body>
<p class="title" name="dromouse"><b>The Dormouse's story</b></p>
<p class="story">Once upon a time there were three little sisters; and their names were
<a href="http://example.com/elsie" class="sister" id="link1"><!-- Elsie --></a>,
<a href="http://example.com/lacie" class="sister" id="link2">Lacie</a> and
<a href="http://example.com/tillie" class="sister" id="link3">Tillie</a>;
and they lived at the bottom of a well.</p>
<p class="story">...</p>
"""

soup=BeautifulSoup(html)

# 上面这句代码便是将本地 index.html 文件打开,用它来创建 soup 对象
# 下面我们来打印一下 soup 对象的内容,格式化输出

print(soup.prettify())

print(soup.title.string)

import requests
s=requests.Session()
xq=s.get('https://sh.fang.lianjia.com/loupan/')
xq.text
soup=BeautifulSoup(xq.text)

soup.prettify()
soup.title.string


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:beautiful HTML soup eau htm

shadowaver@163.com
QQ 540722048

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-1 16:28