【问题标题】:Extracting the Link from this HTML从此 HTML 中提取链接
【发布时间】:2019-11-16 03:07:45
【问题描述】:

我正在尝试使用 beautifulsoup 从该站点中提取一些信息。我熟悉按类/属性提取标签,但是如何从“tr data-url”中提取 url?

import requests
import re
from bs4 import BeautifulSoup


url = "https://www.amcham.org.sg/events-list/?item%5Bdate_start%5D=07%2F05%2F2019&item%5Bdate_end%5D=09/17/2019#page-1"

webpage_response = requests.get(url)
webpage = webpage_response.content
soup = BeautifulSoup(webpage, "html.parser")


table = soup.find_all("tbody")
for i in table:
    rows = i.find_all("tr")
    for row in rows:
        print(row)

<tr data-url="https://www.amcham.org.sg/event/8914">
<td class="date">July 09, 2019</td>

【问题讨论】:

标签: python-3.x


【解决方案1】:

尝试(选择您的代码):

for row in rows:
    myurl = [item['data-url'] for item in bs.find_all('row', attrs={'data-url' : True})]
    print(myurl)

来源:

https://stackoverflow.com/a/24198276/1447509

【讨论】:

    猜你喜欢
    • 2012-04-04
    • 2012-04-10
    • 2019-07-10
    • 1970-01-01
    • 1970-01-01
    • 2013-08-29
    • 2011-06-04
    相关资源
    最近更新 更多