Issue
I am trying to parse the title of links using BeautifulSoup. I have tried various things but just can't get it to work.
The html is behind a login so here's a screenshot:
And here's my latest attempt which I was sure would work but just returns "None".
from bs4 import BeautifulSoup
soup = BeautifulSoup(driver.page_source, 'html.parser')
links = soup.find_all('ul', class_='nav list-group')
print(links)
for link in links:
title = link.get('title')
print(title)
Can anyone see what I am doing wrong?
Solution
This line of code:
links = soup.find_all('ul', class_='nav list-group')
Is not extracting the links, it's extracting the <ul>
tags. Instead, you could try extracting the links with something like:
links = soup.find_all('a', class_='odds')
Then you will be able to loop over them and extract your titles:
for link in links:
print(link['title'])
Answered By - Ari Cooper-Davis
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.