楼主: shadowaver
894 0

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

随心所欲不逾矩

教授

8%

还不是VIP/贵宾

-

威望
0
论坛币
8766 个
通用积分
717.1512
学术水平
18 点
热心指数
19 点
信用等级
13 点
经验
28386 点
帖子
781
精华
0
在线时间
929 小时
注册时间
2007-9-27
最后登录
2024-4-30

+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
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-5-1 01:33