我试图通过lxml从一个网站中提取一些字符,然后是树,然后是xpath。我尝试过使用googlechrome来获得正确的xpath,但是它会打印空括号。在
#imports
from lxml import html
import requests
#get magicseaweed Scripps report
msScrippsPage = requests.get("""http://magicseaweed.com/Scripps-Pier-
La-Jolla-Surf-Report/296/.html""")
#make tree from site
msScrippsTree = html.fromstring(msScrippsPage.content)
#get wave size
msScrippsWave = msScrippsTree.xpath("""/html/body/div[2]/div[5]/div/div[1]/div[2]/div[2]/div/div[2]/div[1]/div/div[1]/div/div/div/div/div[1]/div/div[2]/ul[1]/li[1]/text()""")
print 'ms SCripps: ', msScrippsWave
输出到终端是'msScripps:[]'
你不应该在你的url中使用换行符。当您使用一行时,您的xpath工作。在
编辑:添加完整示例
^{pr2}$相关问题 更多 >
编程相关推荐