python-找不到具有您要求的功能的树生成器:html.parser.您需要安装解析器库吗?
作者:互联网
我正在为AWS上的lambda开发一些代码.
# import libraries
import urllib.request as urllib2
from Packages.bs4 import BeautifulSoup
import time
import Packages.requests as requests
import json
def run(event, context):
try:
# specify the url
quote_page = 'http://money.cnn.com/data/hotstocks/index.html';
page = urllib2.urlopen(quote_page)
soup = BeautifulSoup(page, 'html.parser')
tickers = soup.find_all('a', attrs={'class':'wsod_symbol'})
# api end point http://127.0.0.1:8000/api/TopStock/
for i in range(13,23):
url = 'http://127.0.0.1:8000/api/TopStock/'
headers = {'Content-Type': 'application/json'}
data = {
"ticker": tickers[i].text,
"date": str(time.strftime("%Y-%m-%d"))
}
response = requests.post(url, data=json.dumps(data), headers=headers)
print(response.text)
print( data )
return dict(statusCode=200, body='working')
except Exception as e:
return dict(statusCode=500, body=str(e))
print(run(0,0))
在anaconda所管理的环境中运行良好.
from bs4 import BeautifulSoup
我已经导出了软件包并在项目中运行它
from Packages.bs4 import BeautifulSoup
但我遇到这个问题
Couldn’t find a tree builder with the features you requested:
html.parser. Do you need to install a parser library?
我努力了
> pip install –upgrade lxml
> brew安装libxslt1-dev libxml2 python-dev
无法正常工作:(
running python 3.5
解决方法:
我也在为Lambda开发代码时遇到了这个问题.我正在使用部署包,因此我的项目目录如下所示:
my Lambda function
vendor / bs4 / builder / __ init__.py有一个硬编码参考this_module = sys.modules [‘bs4.builder’]
>我将其更改为this_module = sys.modules [‘vendors.bs4.builder’]
其中vendor是我的第三方软件包目录的名称
>我也为供应商做准备.到bs4进口
bs4 / builder / _htmlparser.如果您使用其他解析器(如lxml或html5lib),请务必更改导入
如果您使用Apex之类的东西,则可以将这两个命令添加到function.json中的构建挂钩中,以自动执行上述步骤.
> sed -i -e’s / bs4.builder / vendors.bs4.builder / g’
./vendors/bs4/builder/__init__.py
> sed -i -e’s / bs4./ vendors.bs4./ g’./vendors/bs4/builder/_htmlparser.py
标签:amazon-web-services,aws-lambda,python,pip 来源: https://codeday.me/bug/20191109/2011646.html