【发布时间】:2019-05-21 16:01:48
【问题描述】:
我是网络抓取的新手,我正在尝试从 https://www.theweathernetwork.com/ca/hourly-weather-forecast/ontario/markham
我曾尝试使用soup.find 抓取该值,但是我不确定参数是否正确。我正在尝试从下面的代码中获取值 17:
<div class="info">
<div class="temp">17</div>
<div class="stackunits">
<div>
<span class="unitwrap">°C</span>
</div>
<div class="feels-like">
<span class="label">Feels like</span>
<span class="value">17</span>
</div>
</div>
</div>
# import libraries
from urllib.request import urlopen
from bs4 import BeautifulSoup
# specify url
quote_page = 'https://www.theweathernetwork.com/ca/hourly-weather-forecast/ontario/markham'
# query website and return html to the variable 'page'
page = urlopen(quote_page)
# parse html using BeautifulSoup and store in variable 'soup'
soup = BeautifulSoup(page, 'html.parser')
# take out the <div> of temp and get its value
atemp_box = soup.find('div', attrs={'class':'temp'})
atemp = atemp_box.text
print(atemp)
AttributeError: 'NoneType' 对象没有属性 'text'
【问题讨论】:
-
你想达到什么结果?
标签: python web-scraping beautifulsoup