Python 我怎么能和BeautifulSoup分开呢?

Python 我怎么能和BeautifulSoup分开呢?,python,beautifulsoup,split,Python,Beautifulsoup,Split,当我只是访问 list = [147975, 07340778] 它表明 soup.select_one(......).text 您能否提前分享如何执行…Thx。您可以使用带有分隔符参数的get_text(): 14797507340778 从bs4导入美化组 def get_值(html:str)->列表: soup=BeautifulSoup(html,'html.parser') 结果=soup.find('td',attrs={'class':'n_td_brand'}) 返回列

当我只是访问

list = [147975, 07340778]
它表明

soup.select_one(......).text
您能否提前分享如何执行…Thx。

您可以使用带有分隔符参数的get_text():

14797507340778
从bs4导入美化组
def get_值(html:str)->列表:
soup=BeautifulSoup(html,'html.parser')
结果=soup.find('td',attrs={'class':'n_td_brand'})
返回列表(map(int,result.get_text(分隔符=“”).split(“”)))
如果名称=“\uuuuu main\uuuuuuuu”:
值=获取值(html=“”147975
07340778”“) 打印(值)
get_text()可以很好地用于:

from bs4 import BeautifulSoup


def get_values(html: str) -> list:
    soup = BeautifulSoup(html, 'html.parser')

    result = soup.find('td', attrs={'class': 'n_td_brand'})

    return list(map(int, result.get_text(separator=' ').split(' ')))


if __name__ == "__main__":
    
    values = get_values(html="""<td class="n_td_brand" width="60">147975<br/>07340778</td>""")

    print(values)
编辑:修改代码以获取列表中的整数值。以下是我对上述答案的替代方法(无拆分)

从bs4导入美化组
数据=“”
147975
07340778 ''' soup=BeautifulSoup(数据'html.parser') 对于汤中的e,选择“td.n\u td\u品牌”: 打印(列表(如字符串))
试试
汤。选择一个(……)。内容
,它由文本节点和元素节点组成。谢谢…它可以工作。很简单。但是你很棒。
列表(汤。选择一个(……)。字符串)
也应该可以。
from bs4 import BeautifulSoup


def get_values(html: str) -> list:
    soup = BeautifulSoup(html, 'html.parser')

    result = soup.find('td', attrs={'class': 'n_td_brand'})

    return list(map(int, result.get_text(separator=' ').split(' ')))


if __name__ == "__main__":
    
    values = get_values(html="""<td class="n_td_brand" width="60">147975<br/>07340778</td>""")

    print(values)
from bs4 import BeautifulSoup
text = '''<td class="n_td_brand" width="60">147975<br/>07340778</td>'''
soup = BeautifulSoup(text, 'html.parser')
s = list(map(int, soup.td.get_text(' ').split()))
print(s)
[147975, 07340778]