在网页上使用BS4时获得[]的回报

时间:2019-08-13 22:47:07

标签: python html web-scraping beautifulsoup python-requests

我正在尝试使用bs4从网站返回数据。我不确定我是针对正确的类还是以错误的方式使用bs4来获取所需的信息表。

我尝试使用不同的方法,但是找不到想要从网站上抓取的信息的正确文档

>>> ```import bs4
>>> import requests
>>> res = requests.get('https://www.5dimes.eu/livelines/livelines.aspx')
>>> type(res)
<class 'requests.models.Response'>
>>> soup = bs4.BeautifulSoup(res.text)
>>> type(soup)
<class 'bs4.BeautifulSoup'>
>>> soup.title
<title>
    Live Lines
</title>
>>> soup.select('.LR Alt')
[]
>>> soup.select('.LSR')
[]
>>> soup.select('h2 > span')
[]
>>> soup = bs4.BeautifulSoup(res.text, 'lxml')
>>> type(soup)
<class 'bs4.BeautifulSoup'>
>>> soup.select('.LR Alt')
[]
>>> 
```

我想至少获得一组球队名称或赔率,但我只是得到[]结果

1 个答案:

答案 0 :(得分:0)

怎么样?

from re import sub
from bs4 import BeautifulSoup
from urllib.request import urlopen
urlpage=urlopen("https://www.5dimes.eu/livelines/livelines.aspx").read()
bswebpage=BeautifulSoup(urlpage)
results=bswebpage.findAll("div",{'class':'SportSubTypes'})
for result in results:
    print(result)

enter image description here

结果:

<span class="Group SportSubType">
<input id="c_23" type="checkbox"/> <a href="#ac_23" rs:checkbox="c_23" title="Scroll to the latest lines for this sport.">Rugby Union Futures</a>
</span>
<span class="Group SportSubType">
<input id="c_24" type="checkbox"/> <a href="#ac_24" rs:checkbox="c_24" title="Scroll to the latest lines for this sport.">Snooker Futures</a>
</span>
</div>