Jordan Freundlich
Jordan Freundlich

Reputation: 79

How to scrape nontext in html?

I am trying to get unique information from each container in a loop. I am using python 3.7 and BeautifulSoup to scrape.

I am running into an issue, where I am trying to get the unique player id number.

Here is the a tag that the number is nested in:

<a cache="true" class="flexpop" content="tabs#ppc" fpopheight="357px" fpopwidth="490px" href="" instance="_ppc" leagueid="216415" playerid="14880" seasonid="2018" tab="null" teamid="-2147483648"> /a>

I have tried a.split() to turn the a tag into a list, where I could just indice the data I want, but that doesnt work.

I tried to use the select function; a.select("playerid") but get empty brackets like this [].

Any help is greatly appreciated! Thanks.

Upvotes: 1

Views: 69

Answers (2)

QHarr
QHarr

Reputation: 84475

You could have used the following syntax as well

from bs4 import BeautifulSoup as bs
h = '<a cache="true" class="flexpop" content="tabs#ppc" fpopheight="357px" fpopwidth="490px" href="" instance="_ppc" leagueid="216415" playerid="14880" seasonid="2018" tab="null" teamid="-2147483648"> /a>'
soup = bs(h,'lxml')
print(soup.select_one('a[playerid]')['playerid'])

Upvotes: 2

Jordan Freundlich
Jordan Freundlich

Reputation: 79

Thanks for User23332, for pointing me in the direction to find the answer.

I just needed to do:

a.attrs['playerid']

Upvotes: 0

Related Questions