【发布时间】:2016-06-06 03:08:49
【问题描述】:
我是 python 3 的新手。我正在将 html 数据与 XPath 配对。我使用pycharm编译我的代码,我的代码如下所示。请帮我解决这个问题(请不要使用美丽的汤)。我知道很多关于使用 python 2 xpath 解析 html 的代码,如果你有一些关于使用 python 3 xpath 解析 html 的材料链接,请告诉我。我已经在 pycharm 中安装了 lxml 和 requests 库。此外,终端默认是python 2.7。提前致谢!
from lxml import html
import requests
page = requests.get('http://econpy.pythonanywhere.com/ex/001.html')
tree = html.fromstring(page.content)
#This will create a list of buyers:
buyers = tree.xpath('//div[@title="buyer-name"]/text()')
#This will create a list of prices
prices = tree.xpath('//span[@class="item-price"]/text()')
print('Buyers: ', buyers)
print('Prices: ', prices)
错误:
/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5
/Users/tianke0711/PycharmProjects/database/Pax_html/xpath_test.py
Traceback (most recent call last):
File
"/Users/tianke0711/PycharmProjects/database/Pax_html/xpath_test.py",
line 1, in <module>
from lxml import html
File
"/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-
packages/lxml/html/__init__.py", line 54, in <module>
from .. import etree
导入错误:
ddlopen(/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/lxml/etree.cpython-35m-darwin.so, 2):库未加载:libxml2.2 .dylib 引用自:/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/lxml/etree.cpython-35m-darwin.so 原因:库版本不兼容:etree.cpython-35m-darwin.so需要12.0.0或更高版本,但libxml2.2.dylib提供10.0.0版本
【问题讨论】:
-
如果您想了解有关此错误的更多信息,请告诉我!我希望你们能帮助我解决这个问题。
标签: html xpath python-3.5