使用 Beautiful Soup 4 提取带有连字符的属性值
Extracting the value of an attribute with a hyphen using Beautiful Soup 4
我正在使用 beautifulsoup 遍历我的标签 4. 我有以下标签内容,无法提取 'data-event-name' 属性的属性值。我要从这里得到“15:02”。
This is the html I need to extract 15:02 from
我已经尝试了很多很多东西,但无法获得这个值。我尝试使用 re 包、getattr python、find、find_all 等。这是我尝试过的一个例子:
for racemeetnum,r1_a in enumerate(r1, start=1):
event1 = getattr(r1_a, 'data-event-name') # doesnt work
<
谢谢@Jack Fleming。我昨晚设法解决了这个问题。最后我的问题不是我找不到属性,而是当找不到属性时我没有捕获错误。我用 try/except 包围了代码,它工作正常。
感谢您的回复!
我正在使用 beautifulsoup 遍历我的标签 4. 我有以下标签内容,无法提取 'data-event-name' 属性的属性值。我要从这里得到“15:02”。
This is the html I need to extract 15:02 from
我已经尝试了很多很多东西,但无法获得这个值。我尝试使用 re 包、getattr python、find、find_all 等。这是我尝试过的一个例子:
for racemeetnum,r1_a in enumerate(r1, start=1):
event1 = getattr(r1_a, 'data-event-name') # doesnt work
<
谢谢@Jack Fleming。我昨晚设法解决了这个问题。最后我的问题不是我找不到属性,而是当找不到属性时我没有捕获错误。我用 try/except 包围了代码,它工作正常。
感谢您的回复!