【问题标题】:How to scrape content from div class using beautifulsoup如何使用 beautifulsoup 从 div 类中抓取内容
【发布时间】:2021-02-25 09:43:45
【问题描述】:

这是我要抓取的 html 页面的一部分

我正在尝试使用 beautifulsoup 获取密码的名称和价值。

我已经尝试了许多使用 find 和 find_all 来获取 div 中包含的内容的解决方案,但我看不出有什么问题...有一个我尝试过的示例:

titles = soup.find_all("div", {"class": "tabTitle-qQlkPW5Y"})

你能帮我解决这个问题吗?

【问题讨论】:

    标签: python html web-scraping beautifulsoup


    【解决方案1】:

    我的解决方案是使用 selenium 来确保页面完全呈现。然后使用漂亮的汤,我们可以浏览它的元素。

    from selenium import webdriver
    driver = webdriver.Chrome(pathToChromeWebDriver)
    url = "https://fr.tradingview.com/markets/cryptocurrencies/global-charts/"
    driver.get(url)
    html = driver.page_source
    
    soup = BeautifulSoup(html, 'html.parser')
    for title in soup.find_all("div", {"class": "tabTitle-qQlkPW5Y"}):
         print(title.string)
    

    【讨论】:

    猜你喜欢
    • 2015-01-05
    • 2019-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-07
    • 2022-09-30
    • 2019-08-14
    • 1970-01-01
    相关资源
    最近更新 更多