python - Issue extracting data using BS4 -
i'm trying extract data website using bs4 can't access exact text need. using following code
name = (soup('td', {'class':'mstat'})) outputs
[<td class="mstat" colspan="3"><span class="r">badges</span></td>] however need class "r". if try access class "r" using following code empty list returned []
name = (soup('td', {'class':'r'})) output
[] i text reads 'badges', text can change length , different can't delete surrounding code.
desired output
'badges' would know i'm doing wrong...
you looking <span> tag instead:
soup('span', class_='r') if want find span tags class inside of td tags mstat class you'll need loop:
spans = [] td in soup('td', class_='mstat'): spans.expand(td('span', class_='r'))
Comments
Post a Comment