我想继续学习webscraping的教程。当我成功编译 当我试图编译网页中列出的代码时,请选择rib via GitHub repo:
from selectorlib import Extractor
import requests
import json
import argparseargparser = argparse.ArgumentParser()
argparser.add_argument('url', help='Amazon Product Details URL')# Create an Extractor by reading from the YAML file
e = Extractor.from_yaml_file('selectors.yml')user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246'
headers = {'User-Agent': user_agent}# Download the page using requests
args = argparser.parse_args()
r = requests.get(args.url, headers=headers)
# Pass the HTML of the page and create
data = e.extract(r.text)
# Print the data
print(json.dumps(data, indent=True))
我得到以下错误:
Traceback (most recent call last):
File "test.py", line 1, in
from selectorlib import Extractor
ImportError: cannot import name 'Extractor' from 'selectorlib' (unknown location)
什么会导致这个问题?我试着在谷歌上搜索,只导入selectorib,从pip安装提取器,只导入exctrator,似乎没有什么能解决这个问题,从教程版本到现在有什么变化吗?你知道吗
编辑: 重新安装selectorlib后,我得到一个不同的错误:
from selectorlib import Extractor
File "/usr/local/lib/python2.7/dist-packages/selectorlib/init.py", line 9, in
from .selectorlib import Extractor # noqa:F401
File "/usr/local/lib/python2.7/dist-packages/selectorlib/selectorlib.py", line 33
def from_yaml_string(cls, yaml_string: str, formatters=None):
错误显示在:yaml\u字符串: 我正在Raspberry Buster(RPI 3B+)上运行python
我已经尝试过使用
pip install selectorlib
并且提取器类的导入对我来说很好。您可能需要执行以下步骤来解决此问题python setup.py install record install_files.txt
xargs rm -rf < install_files.txt
或Windows,请使用powershell命令Get-Content install_files.txt | ForEach-Object {Remove-Item $_ -Recurse -Force}
pip install selectorlib
再次安装包希望这应该清除的问题,因为它的新安装与车轮文件的帮助包。你知道吗
相关问题 更多 >
编程相关推荐