【发布时间】:2015-06-02 06:48:06
【问题描述】:
我只想使用下面给出的方法从链接中提取纬度:“http://hdfc.com/branch-locator”。 纬度在名为“位置”的 javascript 变量中给出。 代码是:
from lxml import html
import re
URL = "http://hdfc.com/branch-locator"
var_lat = re.compile('(?<="latitude":).+(?=")')
main_page = html.parse(URL).getroot()
lat = main_page.xpath("//script[@type='text/javascript']")[1]
ans = re.search(var_lat,str(lat))
print ans
但输出为“无”。在不改变解决问题的方法的情况下,我应该对代码进行哪些更改?
【问题讨论】:
标签: python regex web-scraping lxml