I am trying to parse a page with BS in python.
Here is my code:
years = range(2010,2021)
urls = []
for year in years:
yr = str(year)
url = 'https://www.spotrac.com/nba/contracts/breakdown/'+yr+'/'
webpage = requests.get(url)
content = webpage.content
soup = BeautifulSoup(re.sub("<!--|-->","", content.decode('utf-8')),'lxml')
a = soup.find('table',{'class':'datatable'})
urls.append(a)
I am getting no results. I have double and triple checked the class of the table in the page source. I believe (though I think this is where the error is) - that I have properly coded the soup variable to account for the commented section of the page source.
str(range(2010,2021))
will produce a string 'range(2010, 2021)'
. And then you iterate over each char of that string. So first value of year is r
and so on.
In addition the site requires premium subscription and you need to log in to see data
`
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.