Anaconda / Spyder(Python 3.7)显示AttributeError:“ HTMLParserTreeBuilder”对象没有属性“ store_line_numbers”。熊猫有问题吗?

时间:2020-05-28 01:40:27

标签: python anaconda spyder

我正在尝试学习网络抓取,并且在Anaconda上使用Spyder时遇到问题。我可以在repl.it和python3.8上运行此代码,没问题,但是我在spyder上始终收到相同的错误消息,即“ AttributeError:'HTMLParserTreeBuilder'对象没有属性'store_line_numbers'”。我是python编程的新手,但是我花了很多时间试图确定为什么我无法运行我的代码。我确实看到了别人的问题,他们有类似的问题,并且尝试了执行“ conda install -c conda-forge beautifulsoup4”的解决方案,但是我仍然遇到同样的问题。

我已经完成了conda安装beautifulsoup4,请求和熊猫

据我所知,似乎熊猫存在问题,但我不确定。

任何帮助将不胜感激!我已经附上了下面的所有代码!

import pandas as pd
import requests
from bs4 import BeautifulSoup

#Helena, MT Weather
page = requests.get('https://forecast.weather.gov/MapClick.php?lat=46.5898&lon=-112.0206#.Xs8QUDpKjIU')

soup = BeautifulSoup(page.content, 'html.parser')
week = soup.find(id='seven-day-forecast-body')

items = week.find_all(class_='tombstone-container')

period_names = [item.find(class_= 'period-name').get_text() for item in items]
short_descriptions = [item.find(class_= 'short-desc').get_text() for item in items]
temperatures = [item.find(class_= 'temp').get_text() for item in items]
#print(period_names)
#print(short_descriptions)
#print(temperatures)

weather_info = pd.DataFrame(
  {'period':period_names,
  'short_descriptions': short_descriptions,
  'temperatures': temperatures,
  })

print(weather_info)

weather_stuff.to_csv('weather.csv')

0 个答案:

没有答案