I’m trying to grab a div tag in an html page, but the result is showing an empty list. I’ve provided the code and a picture of the html. The page_text variable is an empty list.
JavaScript
x
7
1
url = 'https://www.highspeedinternet.com/in-your-area?zip=50648'
2
3
page = requests.get(url).text
4
doc = BeautifulSoup(page, "html.parser")
5
page_text = doc.find_all("div", {"data-brand"})
6
print(page_text)
7
Advertisement
Answer
You are close to your goal, just add True
as value in your dict
:
JavaScript
1
2
1
doc.find_all('div',{"data-brand":True})
2
As alternative you can go with css selectors
and list comprehension
to get all the values:
JavaScript
1
2
1
[e.get('data-brand') for e in doc.select('div[data-brand]')]
2
Output:
JavaScript
1
2
1
['CenturyLink', 'Rise Broadband', 'LTD Broadband LLC', 'Viasat', 'HughesNet', 'Heartland Technology', 'Ooma', 'CenturyLink', 'Rise Broadband', 'LTD Broadband LLC', 'Viasat', 'HughesNet', 'Ooma', 'Heartland Technology', 'T-Mobile', 'Verizon Wireless', 'AT&T Wireless', 'Mint', 'Visible']
2