Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用Python抓取航空公司价格_Python_Web Scraping - Fatal编程技术网

用Python抓取航空公司价格

用Python抓取航空公司价格,python,web-scraping,Python,Web Scraping,我一直在尝试创建python代码,以从JFK到LAX的机票价格。 我想获取的价格URL如下: 我最好能得到一份航空公司的时间、起飞时间和价格的清单 我知道 'div class=“GHOFUQ5BGJC>”$210' 对应于价格和价格 'div class=“GHOFUQ5BMFC”>太阳国' 对应于航空公司 到目前为止,这就是我所拥有的 import re import urllib html = "https://www.google.com/flights/#search;f=JFK;t

我一直在尝试创建python代码,以从JFK到LAX的机票价格。 我想获取的价格URL如下:

我最好能得到一份航空公司的时间、起飞时间和价格的清单

我知道 'div class=“GHOFUQ5BGJC>”$210' 对应于价格和价格 'div class=“GHOFUQ5BMFC”>太阳国' 对应于航空公司

到目前为止,这就是我所拥有的

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
重新导入
导入URL库
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='(.+?)'
pattern1=re.compile(re1)
price=re.findall(pattern1,htmltext)
re2='(.+?)'
pattern2=re.compile(re2)
airline=re.findall(模式2,htmltext)
印刷价格
印刷航空公司
有没有办法通过Beauty soup获取价格和航空公司标签?还是我的正则表达式正确? 运行时,代码只会给我两个空列表

我做错了什么?
谢谢

您看过html文件的原始内容了吗?它不包含数据,除非浏览器对该站点中嵌入的javascript进行评估……好的,谢谢,看起来原始html文件中不包含数据。是否还有其他方法可以绕过此问题?@user3628240您可能需要寻找其他数据源。试图从Google搜索结果中刮取数据需要太多的努力。@Jeroko如果网站URL在原始html文档中包含信息,但URL不是自定义的,例如,如果输入目的地和日期后delta.com仍保持为delta.com,是否可以使用网站刮取?感谢一般相关:特别相关: