import requests,jieba
from bs4 import BeautifulSoup
import matplotlib.pyplot as plt
url = 'https://news.so.com/hotnews?src=onebox'
res = requests.get(url)
bea = BeautifulSoup(res.text,'html.parser')
datas = bea.find_all(class_='title')
lists = []
lists2 = []
hot_datas = {}
for data in datas:
lists.append(data.text)
lists = jieba.cut(''.join(lists))
for list in lists:
lists2.append(list)
for x in lists2:
if x in hot_datas:
hot_datas[x] += 1
else:
hot_datas[x] = 1
mins = 1
has = []
ready_del = []
for hot in hot_datas.values():
if hot > mins:
mins = hot
elif hot < mins:
if hot not in has:
for x in [k for k,v in hot_datas.items() if v==hot]:
ready_del.append(x)
has.append(hot)
for x in ready_del:
hot_datas.pop(x)
for hot,lens in hot_datas.items():
print('今日新闻出现频率最高的词:{}'.format(hot))
print('频率:{}'.format(lens))
简单的爬虫程序
导入matplotlib出现
Traceback (most recent call last):
File "c:/Users/xujinhao/Desktop/新闻.py", line 3, in <module>
import matplotlib.pyplot as plt
File "E:\许锦浩至尊文件夹2\许锦浩至尊文件夹\编程\lib\site-packages\matplotlib\__init__.py", line 174, in <module>
_check_versions()
File "E:\许锦浩至尊文件夹2\许锦浩至尊文件夹\编程\lib\site-packages\matplotlib\__init__.py", line 159, in _check_versions
from . import ft2font
ImportError: DLL load failed: 找不到指定的模块。
PS C:\Users\xujinhao>
网上的卸载重装,环境变量 都试过了,环境变量好像是基于Anaconda的,但我用的是vs code