我运行这个python代码,并使用以下命令在Windows上导入lxml库:
Path > install setup.py
已成功安装。
代码是:
from lxml import html
import requests
page = requests.get('http://econpy.pythonanywhere.com/ex/001.html')
tree = html.fromstring(page.text)
#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)
但是当我运行此代码时,会发生以下错误:
ImportError: cannot import name 'html'