我一直在尝试创建python代码来将航空公司的价格从JFK刮到LAX。 我想擦掉的价格的URL在这里:https://www.google.com/flights/#search;f=JFK;t=LAX;d=2014-05-28;r=2014-06-01;tt=o
我最好能得到一份航空公司的时间、起飞时间和价格的清单。
我知道 '分区 class="GHOFUQ5BGJC>" $210 ' corresponds to the price and 'div class="GHOFUQ5BMFC">Sun Country' corresponds to the airline.
到目前为止,这就是我所拥有的
import re
import urllib
html = "https://www.google.com/flights/#search;f=JFK;t=LAX;d=2014-05-28;r=2014-06-01;tt=o"
htmlfile = urllib.urlopen(html)
htmltext = htmlfile.read()
re1 = '<div class="GHOFUQ5BGJC">(.+?)</div>'
pattern1 = re.compile(re1)
price = re.findall(pattern1, htmltext)
re2 ='<div class="GHOFUQ5BMFC">(.+?)</div>'
pattern2 = re.compile(re2)
airline = re.findall(pattern2, htmltext)
print price
print airline
有没有办法通过“靓汤”获取价格和航空公司标签?还是说我和regex走对了路? 运行时,代码只会给我两个空列表。
我做错什么了? 谢谢
目前没有回答
相关问题 更多 >
编程相关推荐