Xpath返回空列表

时间:2017-01-19 10:39:04

标签: python xpath lxml

不知怎的,这似乎不起作用,标题字符串总是返回空

import requests
from lxml import html

headers = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36'}
url ='http://www.hayneedle.com/product/discoverngrowjumperoo.cfm'
page = requests.get(url, headers=headers)
tree = html.fromstring(page.content)
title = tree.xpath('//h1[@class="h2 inline"]//text()')
print(title)

enter image description here 任何帮助都会得到启发,谢谢!

1 个答案:

答案 0 :(得分:0)

我尝试使用vpn并且它确实有效,似乎网站阻止了我的原始IP地址。