简体   繁体   English

美汤没有返回结果

[英]Beautiful Soup not returning results

I am trying to parse a page with BS in python.我正在尝试在 python 中使用 BS 解析页面。

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)' . str(range(2010,2021))将产生一个字符串'range(2010, 2021)' And then you iterate over each char of that string.然后遍历该字符串的每个字符。 So first value of year is r and so on.所以年的第一个值是r等等。

In addition the site requires premium subscription and you need to log in to see data此外,该网站需要付费订阅,您需要登录才能查看数据

` `

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM