gpt4 book ai didi

Python: BeautifulSoup 解析 和
    并更改 class_= 名称

转载 作者:行者123 更新时间:2023-12-01 06:55:45 26 4
gpt4 key购买 nike

我无法获取绿色数据(

displays the HTML structure

yo = requests.get('http://www.nfl.com/schedules/2019/REG11')
soup = bs.BeautifulSoup(yo.text, 'html.parser')
table = soup.find('ul', class_="schedules-table")
print(table) #correctly gathers all data and extraneous data

最佳答案

你看到的绿色数据是html中的注释。可以使用 bs4 中的 Comment 类来获取它 -

from bs4 import BeautifulSoup
from bs4 import Comment
yo = requests.get('http://www.nfl.com/schedules/2019/REG11')
soup = BeautifulSoup(yo.text, 'html.parser')
comment = soup.find_all(string=lambda text: isinstance(text, Comment))

将为您提供页面上的所有评论。您必须自己过滤掉相关评论。

关于Python: BeautifulSoup 解析 </li> 和 <ul> 并更改 class_= 名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58812892/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com