beautifulsoup的简单使用

news2024/9/22 16:46:23

文章目录

  • beautifulsoup
    • 一. beautifulsoup的简单使用
      • 1、安装
      • 2、如何使用
      • 3、对象的种类
    • 二、beautifulsoup的遍历文档树
      • 2.1 子节点
        • .contents 和 .children
      • descendants
      • 2.2 节点内容
        • .string
        • .text
      • 2.3 多个内容
        • .strings
        • **.stripped_strings**
      • 2.4 父节点
        • .parent
        • .parents
    • 三、beautiful的搜索文档树
      • 3.1 find_all
        • name 参数
        • keyword 参数
        • text 参数
        • limit 参数
      • 3.3 find()
      • 3.4 find_parents() 和 find_parent()
    • 四、beautifulsoup的css选择器
    • 4.1 通过标签名查找
    • 4.2 通过类名查找
    • 4.3 id名查找
    • 4.4 组合查找
    • 4.5 属性查找
  • 五.真实案例
    • 1、使用 bs4提取豆瓣图书信息
    • 2、匹配三国演义中的回合 并写入html文本中
    • 3、匹配天气信息 城市与温度
    • 4、匹配广州二手房 房源信息

beautifulsoup

一. beautifulsoup的简单使用

1、安装

Beautiful Soup支持Python标准库中的HTML解析器,还支持一些第三方的解析器,如果我们不安装它,则 Python 会使用 Python默认的解析器,lxml 解析器更加强大,速度更快,推荐安装。

pip install beautifulsoup4

2、如何使用

这是一个html的简单页面

html_doc = """
<html><head><title>The Dormouse's story</title></head>
<body>
<p class="title"><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>
"""

使用BeautifulSoup解析这段代码,能够得到一个 BeautifulSoup 的对象,并能按照标准的缩进格式的结构输出:

from bs4 import BeautifulSoup
soup = BeautifulSoup(html_doc, 'lxml')
# html进行美化
print(soup.prettify())

在这里插入图片描述
这里介绍几个简单的浏览结构化数据的方法

soup.title  # 获取标签title
# <title>The Dormouse's story</title>

soup.title.name   # 获取标签名称
# 'title'

soup.title.string   # 获取标签title内的内容
# 'The Dormouse's story'

soup.title.parent  # 获取父级标签

soup.title.parent.name  # 获取父级标签名称
# 'head'

soup.p
# <p class="title"><b>The Dormouse's story</b></p>

soup.p['class']  # 获取p的class属性值
# 'title'

soup.a
# <a class="sister" href="http://example.com/elsie" id="link1">Elsie</a>

soup.find_all('a')
# [<a class="sister" href="http://example.com/elsie" id="link1">Elsie</a>,
#  <a class="sister" href="http://example.com/lacie" id="link2">Lacie</a>,
#  <a class="sister" href="http://example.com/tillie" id="link3">Tillie</a>]

soup.find(id="link3")  # 获取id为link3的标签
# <a class="sister" href="http://example.com/tillie" id="link3">Tillie</a>

3、对象的种类

Beautiful Soup将复杂HTML文档转换成一个复杂的树形结构,每个节点都是Python对象,所有对象可以归纳为种

Tag , NavigableString , BeautifulSoup , Comment .

  • Tag

通俗点讲就是 HTML 中的一个个标签,Tag 对象与XML或HTML原生文档中的tag相同:

soup = BeautifulSoup('<b class="boldest">Extremely bold</b>')
tag = soup.b
type(tag)
# <class 'bs4.element.Tag'>
  • tag的名字
    soup对象我以下面的例子为准,操作文档树最简单的方法就是告诉它你想获取的tag的name.如果想获取 标签,只要用 `soup.head
soup.head
# <head><title>The Dormouse's story</title></head>

soup.title
# <title>The Dormouse's story</title>
  • name和attributes属性
    Tag有很多方法和属性,现在介绍一下tag中最重要的属性: name和attributes

每个tag都有自己的名字,通过 .name 来获取:

tag.name
# 'b'

tag['class']
# 'boldest'

tag.attrs
# {'class': 'boldest'}

tag的属性可以被添加,删除或修改. 再说一次, tag的属性操作方法与字典一样(了解)

tag['class'] = 'verybold'
tag['id'] = 1
tag
# <blockquote class="verybold" id="1">Extremely bold</blockquote>

del tag['class']
del tag['id']
tag
# <blockquote>Extremely bold</blockquote>

tag['class']
# KeyError: 'class'
print(tag.get('class'))
# None
  • NavigableString(字符串)
    我们既然已经得到了标签的内容,我们想获取具体标签内部的文字怎么办呢?
    字符串常被包含在tag内.Beautiful Soup用 NavigableString 类来包装tag中的字符串。
tag.string
# 'Extremely bold'
type(tag.string)
# <class 'bs4.element.NavigableString'>
  • BeautifulSoup
    BeautifulSoup 对象表示的是一个文档的全部内容.大部分时候,可以把它当作 Tag 对象,是一个特殊的 Tag,我们可以分别获取它的类型,名称,以及属性。
print(type(soup.name))
# <class 'str'>
print(soup.name)
# [document]
print(soup.attrs)
# {} 空字典
  • Comment
    html_doc=‘

soup = BeautifulSoup(html_doc, ‘html.parser’)

print(soup.a.string) # Elsie
print(type(soup.a.string)) # <class ‘bs4.element.Comment’>

二、beautifulsoup的遍历文档树

我们使用下面的例子,我们来演示下面的几个功能:

html_doc = """
<html><head><title>The Dormouse's story</title></head>
    <body>
<p class="title"><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>
"""

from bs4 import BeautifulSoup
soup = BeautifulSoup(html_doc, 'html.parser')

2.1 子节点

一个Tag可能包含多个字符串或其它的Tag,这些都是这个Tag的子节点.Beautiful Soup提供了许多操作和遍历子节点的属性.

.contents 和 .children

tag的 .contents 属性可以将tag的子节点以列表的方式输出:

head_tag = soup.head
head_tag
# <head><title>The Dormouse's story</title></head>

head_tag.contents
[<title>The Dormouse's story</title>]

title_tag = head_tag.contents[0]
title_tag
# <title>The Dormouse's story</title>
title_tag.contents
# [u'The Dormouse's story']

字符串没有 .contents 属性,因为字符串没有子节点:

text = title_tag.contents[0]
text.contents
# AttributeError: 'NavigableString' object has no attribute 'contents'

.children它返回的不是一个 list,不过我们可以通过遍历获取所有子节点。我们打印输出 .children 看一下,可以发现它是一个 list 生成器对象
通过tag的 .children 生成器,可以对tag的子节点进行循环:

print(title_tag.children)       # <list_iterator object at 0x101b78860>
print(type(title_tag.children)) # <class 'list_iterator'>


for child in title_tag.children:
    print(child)
    # The Dormouse's story

descendants

.contents.children 属性仅包含tag的直接子节点.例如,<head>标签只有一个直接子节点<title>

head_tag.contents
# [<title>The Dormouse's story</title>]

但是<title>标签也包含一个子节点:字符串 “The Dormouse’s story”,这种情况下字符串 “The Dormouse’s story”也属于<head>标签的子孙节点.

.descendants 属性可以对所有tag的子孙节点进行递归循环 。

for child in head_tag.descendants:
    print(child)
    # <title>The Dormouse's story</title>
    # The Dormouse's story

上面的例子中, <head>标签只有一个子节点,但是有2个子孙节点:<head>节点和<head>的子节点, BeautifulSoup 有一个直接子节点(<html>节点),却有很多子孙节点:

len(list(soup.children))
# 1
len(list(soup.descendants))
# 25

2.2 节点内容

.string

如果tag只有一个 NavigableString 类型子节点,那么这个tag可以使用 .string 得到子节点。如果一个tag仅有一个子节点,那么这个tag也可以使用 .string 方法,输出结果与当前唯一子节点的 .string 结果相同。

通俗点说就是:如果一个标签里面没有标签了,那么 .string 就会返回标签里面的内容。如果标签里面只有唯一的一个标签了,那么 .string 也会返回最里面的内容。例如:

print (soup.head.string)
#The Dormouse's story
# <title><b>The Dormouse's story</b></title>
print (soup.title.string)
#The Dormouse's story

如果tag包含了多个子节点,tag就无法确定,string 方法应该调用哪个子节点的内容, .string 的输出结果是 None

print (soup.html.string)
#None
.text

如果tag包含了多个子节点, text则会返回内部所有文本内容

print (soup.html.text)

注意:

strings和text都可以返回所有文本内容

区别:text返回内容为字符串类型 strings为生成器generator

2.3 多个内容

.strings .stripped_strings 属性

.strings

获取多个内容,不过需要遍历获取,比如下面的例子:

for string in soup.strings:
    print(repr(string))
    
    
'''
  '\n'
"The Dormouse's story"
'\n'
'\n'
"The Dormouse's story"
'\n'
'Once upon a time there were three little sisters; and their names were\n'
'Elsie'
',\n'
'Lacie'
' and\n'
'Tillie'
';\nand they lived at the bottom of a well.'
'\n'
'...'
'\n'  
    
'''    
.stripped_strings

输出的字符串中可能包含了很多空格或空行,使用 .stripped_strings 可以去除多余空白内容

for string in soup.stripped_strings:
    print(repr(string))


'''

"The Dormouse's story"
"The Dormouse's story"
'Once upon a time there were three little sisters; and their names were'
'Elsie'
','
'Lacie'
'and'
'Tillie'
';\nand they lived at the bottom of a well.'
'...'

'''

2.4 父节点

.parent

通过 .parent 属性来获取某个元素的父节点.在例子“爱丽丝”的文档中,<head>标签是<title>标签的父节点:

title_tag = soup.title
title_tag
# <title>The Dormouse's story</title>
title_tag.parent
# <head><title>The Dormouse's story</title></head>

文档的顶层节点比如<html>的父节点是 BeautifulSoup 对象:

html_tag = soup.html
type(html_tag.parent)
# <class 'bs4.BeautifulSoup'>
.parents

通过元素的 .parents 属性可以递归得到元素的所有父辈节点,下面的例子使用了 .parents 方法遍历了<a>标签到根节点的所有节点.

link = soup.a
link
# <a class="sister" href="http://example.com/elsie" id="link1">Elsie</a>
for parent in link.parents:
    if parent is None:
        print(parent)
    else:
        print(parent.name)
# p
# body
# html
# [document]
# None

三、beautiful的搜索文档树

3.1 find_all

find_all( name , attrs , recursive , string , **kwargs )

  • name: 一个字符串或正则表达式,用于指定要查找的标签名称。如果传入 True,则匹配任何标签。

  • attrs: 一个字典或 None。如果传入字典,字典中的键值对将被用来匹配标签的属性。例如,{‘class’: ‘foo’} 将匹配所有具有 class=“foo” 属性的标签。

  • recursive: 一个布尔值。如果为 True(默认值),则在所有后代中递归搜索匹配的标签;如果为 False,则只在当前标签的直接子标签中搜索。

  • string: 一个字符串或正则表达式,用于匹配标签内的文本。如果传入字符串,Beautiful Soup 将查找包含该字符串的标签;如果传入正则表达式,则使用该正则表达式来匹配标签内的文本。

  • **kwargs: 额外的关键字参数,这些参数将被传递给 find_all 方法的内部实现,用于进一步定制搜索条件。

soup.find_all("title")
# [<title>The Dormouse's story</title>]

soup.find_all("p", "title")
# [<p class="title"><b>The Dormouse's story</b></p>]

soup.find_all("a")
# [<a class="sister" href="http://example.com/elsie" id="link1">Elsie</a>,
#  <a class="sister" href="http://example.com/lacie" id="link2">Lacie</a>,
#  <a class="sister" href="http://example.com/tillie" id="link3">Tillie</a>]

soup.find_all(id="link2")
# [<a class="sister" href="http://example.com/lacie" id="link2">Lacie</a>]

import re
# 模糊查询 包含sisters的就可以
soup.find(string=re.compile("sisters"))
# 'Once upon a time there were three little sisters; and their names were\n'

有几个方法很相似,还有几个方法是新的,参数中的 stringid 是什么含义? 为什么 find_all("p", "title") 返回的是CSS Class为”title”的<p>标签? 我们来仔细看一下 find_all() 的参数.

name 参数

name 参数可以查找所有名字为 name 的tag,字符串对象会被自动忽略掉.

简单的用法如下:

soup.find_all("title")
# [<title>The Dormouse's story</title>]
  • <1> 传字符串
    最简单的过滤器是字符串.在搜索方法中传入一个字符串参数,Beautiful Soup会查找与字符串完整匹配的内容,下面的例子用于查找文档中所有的标签
soup.find_all('b')
# [<b>The Dormouse's story</b>]
  • <2> 传正则表达式
import re
for tag in soup.find_all(re.compile("^b")):
    print(tag.name)
# body
# b
  • <3> 传列表
    如果传入列表参数,Beautiful Soup会将与列表中任一元素匹配的内容返回.下面代码找到文档中所有<a>标签和<b>标签
soup.find_all(["a", "b"])
# [<b>The Dormouse's story</b>,
#  <a class="sister" href="http://example.com/elsie" id="link1">Elsie</a>,
#  <a class="sister" href="http://example.com/lacie" id="link2">Lacie</a>,
#  <a class="sister" href="http://example.com/tillie" id="link3">Tillie</a>]
keyword 参数

如果一个指定名字的参数不是搜索内置的参数名,搜索时会把该参数当作指定名字tag的属性来搜索,如果包含一个名字为 id 的参数,Beautiful Soup会搜索每个tag的”id”属性.

soup.find_all(id='link2')
# [<a class="sister" href="http://example.com/lacie" id="link2">Lacie</a>]

import re
# 超链接包含elsie标签
print(soup.find_all(href=re.compile("elsie")))
# [<a class="sister" href="http://example.com/elsie" id="link1">Elsie</a>]
# 以The作为开头的字符串
print(soup.find_all(text=re.compile("^The"))) 
# ["The Dormouse's story", "The Dormouse's story"]
# class选择器包含st的节点
print(soup.find_all(class_=re.compile("st")))

搜索指定名字的属性时可以使用的参数值包括 字符串 , 正则表达式 , 列表, True .
下面的例子在文档树中查找所有包含 id 属性的tag,无论 id 的值是什么:

soup.find_all(id=True)
# [<a class="sister" href="http://example.com/elsie" id="link1">Elsie</a>,
#  <a class="sister" href="http://example.com/lacie" id="link2">Lacie</a>,
#  <a class="sister" href="http://example.com/tillie" id="link3">Tillie</a>]

使用多个指定名字的参数可以同时过滤tag的多个属性:

soup.find_all(href=re.compile("elsie"), id='link1')
# [<a class="sister" href="http://example.com/elsie" id="link1">three</a>]

在这里我们想用 class 过滤,不过 class 是 python 的关键词,这怎么办?加个下划线就可以:

print(soup.find_all("a", class_="sister"))

'''
[<a class="sister" href="http://example.com/elsie" id="link1">Elsie</a>,
<a class="sister" href="http://example.com/lacie" id="link2">Lacie</a>,
<a class="sister" href="http://example.com/tillie" id="link3">Tillie</a>
]

'''

通过 find_all() 方法的 attrs 参数定义一个字典参数来搜索包含特殊属性的tag:
]

data_soup.find_all(attrs={"data-foo": "value"})
# [<div data-foo="value">foo!</div>]

注意:如何查看条件id和class同时存在时的写法

data_soup.find_all(attrs={"data-foo": "value"})
# [<div data-foo="value">foo!</div>]

注意:如何查看条件id和class同时存在时的写法

print(soup.find_all('b', class_="story", id="x"))
print(soup.find_all('b', attrs={"class":"story", "id":"x"}))
text 参数

通过 text 参数可以搜搜文档中的字符串内容.与 name 参数的可选值一样, text 参数接受 字符串 , 正则表达式 , 列表, True.

import re

print(soup.find_all(text="Elsie"))
# ['Elsie']

print(soup.find_all(text=["Tillie", "Elsie", "Lacie"]))
# ['Elsie', 'Lacie', 'Tillie']

# 只要包含Dormouse就可以
print(soup.find_all(text=re.compile("Dormouse")))
# ["The Dormouse's story", "The Dormouse's story"]
limit 参数

find_all() 方法返回全部的搜索结构,如果文档树很大那么搜索会很慢.如果我们不需要全部结果,可以使用 limit 参数限制返回结果的数量.效果与SQL中的limit关键字类似,当搜索到的结果数量达到 limit 的限制时,就停止搜索返回结果.

print(soup.find_all("a",limit=2))
print(soup.find_all("a")[0:2])

'''
[<a class="sister" href="http://example.com/elsie" id="link1">Elsie</a>, 
<a class="sister" href="http://example.com/lacie" id="link2">Lacie</a>]
'''

3.3 find()

find(name , attrs , recursive , string , **kwargs )

  • name: 一个字符串或正则表达式,用于指定要查找的标签名称。如果设置为 None 或省略,则匹配任何标签。

  • attrs: 一个字典,用于指定要查找的标签的属性。如果属性字典中的键值对完全匹配一个标签的属性,则该标签会被返回。如果设置为 None 或省略,则不进行属性匹配。

  • recursive: 一个布尔值。如果为 True(默认值),则在所有后代中递归搜索匹配的标签;如果为 False,则只在当前标签的直接子标签中搜索。

  • string: 一个字符串或正则表达式,用于匹配标签内的文本。如果传入字符串,find 将查找包含该字符串的第一个标签;如果传入正则表达式,则使用该正则表达式来匹配标签内的文本。

  • **kwargs: 额外的关键字参数,这些参数可以用于指定其他搜索条件,如 limit(限制返回的结果数量)等。

find_all() 方法将返回文档中符合条件的所有tag,尽管有时候我们只想得到一个结果.比如文档中只有一个<body>标签,那么使用 find_all() 方法来查找<body>标签就不太合适, 使用 find_all 方法并设置 limit=1 参数不如直接使用 find() 方法.下面两行代码是等价的:

soup.find_all('title', limit=1)
# [<title>The Dormouse's story</title>]

soup.find('title')
# <title>The Dormouse's story</title>

唯一的区别是 find_all() 方法的返回结果是值包含一个元素的列表,而 find() 方法直接返回结果.

find_all() 方法没有找到目标是返回空列表, find() 方法找不到目标时,返回 None .

print(soup.find("nosuchtag"))
# None

soup.head.title 是 tag的名字 方法的简写.这个简写的原理就是多次调用当前tag的 find() 方法:

soup.head.title
# <title>The Dormouse's story</title>

soup.find("head").find("title")
# <title>The Dormouse's story</title>

3.4 find_parents() 和 find_parent()

a_string = soup.find(text="Lacie")
print(a_string)  # Lacie

print(a_string.find_parent())
# <a class="sister" href="http://example.com/lacie" id="link2">Lacie</a>
print(a_string.find_parents())
print(a_string.find_parent("p"))
'''
<p class="story">
    Once upon a time there were three little sisters; and their names were
    <a class="sister" href="http://example.com/elsie" id="link1">Elsie</a>,
    <a class="sister" href="http://example.com/lacie" id="link2">Lacie</a> and
    <a class="sister" href="http://example.com/tillie" id="link3">Tillie</a>;
    and they lived at the bottom of a well.
</p>

'''

四、beautifulsoup的css选择器

我们在写 CSS 时,标签名不加任何修饰,类名前加点,id名前加 #,在这里我们也可以利用类似的方法来筛选元素,用到的方法是 **soup.select(),**返回类型是 list

4.1 通过标签名查找

print(soup.select("title"))  #[<title>The Dormouse's story</title>]
print(soup.select("b"))      #[<b>The Dormouse's story</b>]

4.2 通过类名查找

print(soup.select(".sister")) 

'''
[<a class="sister" href="http://example.com/elsie" id="link1">Elsie</a>, 
<a class="sister" href="http://example.com/lacie" id="link2">Lacie</a>, 
<a class="sister" href="http://example.com/tillie" id="link3">Tillie</a>]

'''

4.3 id名查找

print(soup.select("#link1"))
# [<a class="sister" href="http://example.com/elsie" id="link1">Elsie</a>]

4.4 组合查找

组合查找即和写 class 文件时,标签名与类名、id名进行的组合原理是一样的,例如查找 p 标签中,id 等于 link1的内容,二者需要用空格分开。

print(soup.select("p #link2"))

#[<a class="sister" href="http://example.com/lacie" id="link2">Lacie</a>]

直接子标签查找

print(soup.select("p > #link2"))
# [<a class="sister" href="http://example.com/lacie" id="link2">Lacie</a>]

查找既有class也有id选择器的标签

a_string = soup.select(".story#test")

查找有多个class选择器的标签

a_string = soup.select(".story.test")

查找有多个class选择器和一个id选择器的标签

a_string = soup.select(".story.test#book")

4.5 属性查找

查找时还可以加入属性元素,属性需要用中括号括起来,注意属性和标签属于同一节点,所以中间不能加空格,否则会无法匹配到。

print(soup.select("a[href='http://example.com/tillie']"))
#[<a class="sister" href="http://example.com/tillie" id="link3">Tillie</a>]

select 方法返回的结果都是列表形式,可以遍历形式输出,然后用 get_text() 方法来获取它的内容:

for title in soup.select('a'):
    print (title.get_text())

'''
Elsie
Lacie
Tillie
'''

五.真实案例

1、使用 bs4提取豆瓣图书信息

在这里插入图片描述

from bs4 import BeautifulSoup
soup = BeautifulSoup(open('../素材/豆瓣.html', 'r'), 'lxml')

# 匹配图片地址
print(soup.find_all('img'))
for i in soup.find_all('img'):
    print(i.attrs)  # 获取图片连接地址

# 获取标题 简介 评分等信息

h = soup.find_all('div', class_='detail-frame')
for i in h:
    # print(i.text)  # 获取当前节点里所有的文本内容
    print(i.a.text)  # 获取标题  超链接里面的文本内容
    print(i.find('span', class_='font-small color-lightgray').text)  # 获取评分
    print(i.find('p', 'color-gray').text)  # 获取简介
    print(i.find_all('p')[-1].text)  # 获取简介


2、匹配三国演义中的回合 并写入html文本中

from bs4 import BeautifulSoup

# 进行请求
# 获取页面内容
con = open('../素材/三国演义.html', 'r')
# 参数 页面内容  解析器
soup = BeautifulSoup(con, 'lxml')
title_list = soup.select('.book-mulu>ul>li>a')

with open('./爬取三国演义.html', 'w', encoding='GBK') as f:
    for t in title_list:
        # 输出文章标题
        title = t.text
        # 获取文章地址
        href = t['href']
        url = 'https://www.shicimingju.com/'+href
        print(url)
        f.write(f"<a href='{url}' target='_blank'>{title}</a>"+'<br />')

3、匹配天气信息 城市与温度

只要城市与气温。
在这里插入图片描述
在这里插入图片描述

from bs4 import BeautifulSoup
ALL_DATA = []
soup = BeautifulSoup(open('../素材/匹配天气.html', 'r'), 'lxml')
conMidtab = soup.find('div',class_='conMidtab')
# 获取所有的天气信息表格
tables = conMidtab.find_all('table')
for table in tables:
    # 过滤掉标题行
    trs = table.find_all('tr')[2:]
    for index, tr in enumerate(trs):
        tds = tr.find_all('td')
        # print(index, tds)
        # 获取城市和天气
        city_td = tds[0]
        temp_td = tds[3]
        # 过滤掉表格左侧的省/直辖市
        if index == 0:
            city_td = tds[1]
            temp_td = tds[4]
        city_td = list(city_td.stripped_strings)[0]
        temp_td = list(temp_td.stripped_strings)[0]
        ALL_DATA.append({'city':city_td,'temp':temp_td})

print(ALL_DATA)



4、匹配广州二手房 房源信息

from bs4 import BeautifulSoup

soup = BeautifulSoup(open('../素材/二手房详情页.html', 'r'), 'lxml')
# 通过select方式进行获取
# sidefixedbox = soup.select('.sidefixedbox#sidefixedbox')
# print(sidefixedbox[0].text)
# 通过属性
sidefixedbox = soup.find('div', attrs={'class': 'sidefixedbox', 'id': 'sidefixedbox'}).text
print(sidefixedbox)

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2034394.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

AD如何在封装制作时添加禁止铺铜区域?

在PCB封装库中&#xff0c;选择“Top Layer”层执行菜单命令“放置→多边形铺铜挖空”&#xff0c; 然后画好所需要的挖空的区域即可&#xff0c;如果是设计完PCB之后才来进行铺铜挖空的&#xff0c;可以在添加完铺铜挖空之后选中器件右击点选“Update PCB With All”&#x…

PyFluent入门之旅(10)Fluent Python Console

之前的文章中都在介绍如何在Fluent外部环境使用PyFluent&#xff0c;那么是否有可能在Fluent内部使用PyFluent呢&#xff1f; 自Ansys 2023 R1开始&#xff0c;Ansys Fluent的内置控制台支持Python命令&#xff0c;这使在Fluent内部控制台使用PyFluent成为了可能。 准备工作 …

【SpringBoot】9 定时任务(Quartz)

介绍 实现方式 java定时任务调度的实现方式&#xff1a;Timer&#xff0c;ScheduledExecutor&#xff0c;Spring Scheduler&#xff0c;JCron Tab&#xff0c;Quartz 等。 Quartz Quartz是一个由Java开发的开源项目&#xff0c;它可以与J2EE、J2SE应用程序相结合也可以单独…

直播预约|8月14日,无人系统开发阶段故障注入与安全测试详解

电机失效故障硬件在环仿真 01 培训背景 卓翼飞思实验室暑期公益培训(第六期)将于8月14日&#xff0c;19:00开启&#xff01;通过【飞思实验室】视频号线上直播&#xff0c;由中南大学计算机学院特聘副教授&#xff0c;RflySim平台总研发负责人戴训华副教授主讲。 第六期培训将…

Navicat Premium15 下载与安装(免费版)以及链接SqlServer数据库

转自:https://blog.csdn.net/m0_75188141/article/details/139842565

Hi910X 系列恒压恒流 BUCK 控制器

1. 产品介绍 Hi910X 是一系列外围电路简洁的宽输入电压降压 BUCK 恒压恒流驱动器&#xff0c;适用于 8-150V 输入电压范围的 DCDC 降压应用。Hi9100、Hi9101、Hi9102、Hi9103智芯半导体降压恒压系列 Hi910X 采用我司专利算法&#xff0c;实现高精度的降压恒压恒流。支持输出…

CV每日论文--2024.7.24

1 、AutoAD-Zero: A Training-Free Framework for Zero-Shot Audio Description 中文标题&#xff1a;T2V-CompBench&#xff1a;组合文本到视频生成的综合基准AutoAD-Zero&#xff1a;零样本音频描述的免训练框架 简介&#xff1a;我们的目标是以无需训练的方式为电影和电视剧…

入门岛第2关Python基础知识

任务一 :Python实现wordcount 实现一个wordcount函数&#xff0c;统计英文字符串中每个单词出现的次数。返回一个字典&#xff0c;key为单词&#xff0c;value为对应单词出现的次数。 任务二:debug流程 安装好Python插件在 远程服务器中 在程序中打断点 debug 点击VSCode侧…

haproxy是什么?以及haproxy基础实验

目录 一、什么是负载均衡&#xff1f; 二、为什么要用haproxy&#xff1f; 三、haproxy的基本部署实验&#xff1a; 3.1 基本配置实验 环境准备&#xff1a; 详细步骤&#xff1a; 3.2 haproxy-多进程与多线程实验&#xff1a; 多进程&#xff1a; 多线程&#xff1a;…

【云服务器】 阿里云服务器免费试用3个月 不用学生认证

审核大大&#xff0c;这个真的不是广告呀...也是我琢磨了一下发现的一个方式&#xff0c;阿里云会找我打广告吗&#xff1f;&#xff1f; 这个羊毛不用学生认证&#xff01;&#xff01;只需登录和实名认证和即可 学生实名认证是送优惠券300&#xff0c;我没用上&#xff0c;…

Google 开发者大会(北京站) Play政策会议内容解读

2024年Google开发者大会的会议已结束&#xff0c;很庆幸自己参与了 Google Play 专场&#xff1a;全球视野&#xff0c;助力出海创新与增长 [13:00 - 15:10] 的工作坊内容&#xff0c;受益匪浅。 Google对未来Play市场的愿景&#xff0c;Play Console后台的全新功能&#xff0…

漏洞复现-XXL-JOB accessToken 存在身份认证绕过漏洞

1.漏洞描述 XXL-JOB是许雪里&#xff08;XXL-JOB&#xff09;社区的一款基于java语言的分布式任务调度平台。 2.影响版本 XXL-JOB < 2.2.0 3.影响范围 4.漏洞分析 首先通过微步的漏洞通报说是 src/main/resources/application.properties 默认情况下是非空的&#xff…

HAPropy全功能详解

在一个lvs的环境中&#xff0c;如果服务器出现故障&#xff0c;按照lvs的策略却依然会将访问方式到故障服务器&#xff0c;必然是没有回应的结果&#xff0c;在一个集群中&#xff0c;一台服务器出现故障&#xff0c;理应灵活的去寻找没有故障的服务器&#xff0c;这种方法可以…

免费【2024】springboot 个人博客系统的设计与实现

博主介绍&#xff1a;✌CSDN新星计划导师、Java领域优质创作者、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java技术领域和学生毕业项目实战,高校老师/讲师/同行前辈交流✌ 技术范围&#xff1a;SpringBoot、Vue、SSM、HTML、Jsp、PHP、Nodejs、Python、爬虫、数据可视化…

C语言寻找波峰值

做到项目有需要压力采集的处理&#xff0c;为了便于在程序中计算采集的波形数据&#xff0c;这里简单写一个查找波峰的程序 首先用Python把波峰点找出来&#xff0c; 方便我们对照 我这里主要是判断波峰&#xff0c;波谷的原理也大同小异&#xff0c;改一下程序就行 波峰判断…

顺丰科技2025届校招面试流程、SHL测评题型、笔试题库及答案解析

顺丰科技有限公司成立于2009年&#xff0c;是顺丰旗下专注供应链数智解决方案的科技服务商。我们深耕于供应链数智化十余年&#xff0c;致力于构建卓越的智慧供应链&#xff0c;重塑全球商业文明和生产方式。我们基于对供应链场景的深度理解和行业头部公司的数智化实战经验&…

手机CPU性能天梯图(2024年8月),含安兔兔/GB6/3DMark跑分

原文地址&#xff08;高清无水印原图/持续更新/含榜单出处链接&#xff09;&#xff1a; 2024年8月手机处理器天梯图 2024年8月1日更新日志&#xff1a;由于近期并未有新处理器发布&#xff0c;故只做常规更新&#xff1b;移除鲁大师天梯图&#xff1b;补充其它天梯图数量。 -…

介质套检测方案,如何提升检测效率?

介质套是一种用于保护和装饰电子设备的外壳或套子。这种套子通常由各种材料制成&#xff0c;如硅胶、塑料、皮革等&#xff0c;具有不同的质地和外观风格。介质套可适用于各种电子设备&#xff0c;如手机、平板电脑、笔记本电脑等&#xff0c;为其提供额外的保护&#xff0c;并…

S32G3系列芯片如何从外置flash进行Boot启动?

《S32G3系列芯片——Boot详解》系列——S32G3系列芯片如何从外置flash进行Boot启动&#xff1f; 一、概述二、基于QuadSPI的boot2.1 基于QuadSPI的boot方式概述2.2 IO配置2.3 时钟配置2.4 QuadSPI具体配置参数2.5 系统重置后BootROM对闪存的要求2.6 应用程序对闪存配置的影响 三…

审稿超慢的顶刊,年年投稿量爆涨?年发文量1800+,国人投稿占优!

点击关注&#xff1a;关注GZH【欧亚科睿学术】&#xff0c;GET完整版2023JCR分区列表&#xff01; &#x1f525; &#x1f525; &#x1f525; &#x1f525; ELSEVIER旗下1区TOP刊 今天小编给大家介绍的是一本计算机人工智能领域的期刊《Engineering Applications of…