from lxml import html
import requests
pagina = 'http://www.beleggen.nl/amx'
page = requests.get(pagina)
tree = html.fromstring(page.text)
aandeel = tree.xpath('//a[@title="Imtech"]/text()')
print aandeel
Run Code Online (Sandbox Code Playgroud)
这部分有效,但我想阅读不同标题的多行,是否可以将"Imtech"部分更改为变量?
像这样的东西,它显然不起作用,但我哪里出错了?或者这不容易吗?
FondsName = "Imtech"
aandeel = tree.xpath('//a[@title="%s"]/text()')%(FondsName)
print aandeel
Run Code Online (Sandbox Code Playgroud)