BeautifulSoup getting content behind multiple
levels

后端 未结 3 1735
旧巷少年郎
旧巷少年郎 2021-01-27 14:03

How can I get the time data behind two \"divs\" with BeautifulSoup?

6:00.00

I\'ve tried the f

3条回答
  •  耶瑟儿~
    2021-01-27 14:27

    Try this to get the time you wish to scrape:

    import requests
    from bs4 import BeautifulSoup
    
    page = requests.get("https://www.energystorageexchange.org/projects/2") 
    soup = BeautifulSoup(page.content, 'lxml')
    for item in soup.select("label.new_font"):
        if "HH:MM" in item.text:
            itemval = item.find_parent().find_next_sibling().text.strip()
            print(itemval)
    

    Output:

    6:00.00
    

提交回复
热议问题