尝试使用汤筛时出现NotImplementedError

时间:2019-02-08 10:32:19

标签: python web-scraping beautifulsoup python-requests

因此,我同时使用pip和easy_install下载了汤筛。对于pip,它表示已满足要求,对于easy_install,它表示处理汤筛的依赖关系 完成了汤筛的处理依赖性。我相信那时一切都会很好。但是,当我编码时,我得到一个错误。这是我的代码:

import requests
from bs4 import BeautifulSoup as bs
import re

res = requests.get('http://abacus.realendpoints.com/ConsoleTemplate.aspx?act=qlrd&req=nav&mop=abacus!main&pk=ed5a81ad-9367-41c8-aa6b-18a08199ddcf&ab-eff=1000&ab-tox=0.1&ab-nov=1&ab-rare=1&ab-pop=1&ab-dev=1&ab-prog=1.0&ab-need=1&ab-time=1543102810')
soup = bs(res.content, 'lxml') 
scripts = soup.select('script')
searchText = ''
for script in scripts:
    if 'Block abacus-spend-graph' in  script.text:
        searchText = script.text
        break

if len(searchText) > 0:
    items = str(script).split('series:')
    item = items[2].split('exporting')[0][:-15]
    p1 = re.compile('name:(.*)]')
    p2 = re.compile('(\d+\.\d+)+')
    it = re.finditer(p1, item)
    names = [match.group(1).split(',')[0].strip().replace("'",'') for match in it]
    it2 = re.finditer(p2, item)
    allNumbers = [float(match.group(1)) for match in it2]
    actualAnnuals = allNumbers[0::2]
    abacusAnnuals = allNumbers[1::2]
    print('actuals: ', actualsAnnuals)
    print('abacus:', abacusAnnuals)

当我尝试编译并运行它时,会出现这种错误:

UserWarning: The soupsieve package is not installed. CSS selectors cannot be used.
  'The soupsieve package is not installed. CSS selectors cannot be used.'
Traceback (most recent call last):
  File "other.py", line 7, in <module>
    scripts = soup.select('script')
  File "element.py", line 1373, in select
    "Cannot execute CSS selectors because the soupsieve package is not installed."
NotImplementedError: Cannot execute CSS selectors because the soupsieve package is not installed.

我不确定自己在做什么错。谢谢您的帮助。

0 个答案:

没有答案