仿照b站上自己写的Google Flight的一段查票代码

昨天看到论坛里有人发帖分享了b站上一个自己写查票python代码的视频, 很多人求代码。于是我自己照葫芦画瓢写了一个。 虽然我是CS PhD,但本身做的比较底层平时都用c, python路人水平。所以是一个非常naive的code,但还是希望能够帮助到大家。


喜欢的话帮忙点个star哈哈哈哈
10赞
Traceback (most recent call last):
  File "C:\Users\chenh\Desktop\FlightTicket-master\flightTicketTracker.py", line 5, in <module>
    from playsound import playsound
ModuleNotFoundError: No module named 'playsound'

如何解决

pip install playsound

Traceback (most recent call last):
  File "C:\Users\chenh\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start
    self.process = subprocess.Popen(cmd, env=self.env,
  File "C:\Users\chenh\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\chenh\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 1307, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\chenh\Desktop\FlightTicket-master\flightTicketTracker.py", line 50, in <module>
    search(frequency)
  File "C:\Users\chenh\Desktop\FlightTicket-master\flightTicketTracker.py", line 33, in search
    driver = webdriver.Chrome()
  File "C:\Users\chenh\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
    self.service.start()
  File "C:\Users\chenh\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

如何解决?

谢谢,又有了新问题见上面。

应该是你的chrome路径没被搜索到,试试在init driver的时候在括号里直接指定chrome的路径

谢谢,搞定了!厉害!

楼主我在你的代码上加了IFTTT通知的功能 :grinning:这样就能在手机上实时收到通知了
已经把代码pull request到GitHub了,你觉得可以的话就通过一下

(或许之后能一起整一个直接查美联航官网的? :joy:

最好能让网页后台运行(或者不跳到最前面),总是跳到最前端打扰正在干的活,只有一个屏幕

你好 请问这个error怎么解决?谢谢!

Traceback (most recent call last):
  File "C:/Users/Frank Wu/Desktop/Flight/Try 001.py", line 49, in <module>
    search(frequency)
  File "C:/Users/Frank Wu/Desktop/Flight/Try 001.py", line 33, in search
    driver.get(url)
AttributeError: 'str' object has no attribute 'get'

问题已解决 多谢

已经Merge了

File "C:\Users\chenh\Desktop\FlightTicket-master2\FlightTicket-master\flightTicketTracker.py", line 40, in <module>
    raise Exception("You need to fill in the API_KEY in the directory.")
Exception: You need to fill in the API_KEY in the directory.

请问如何解决。我已经把API_Key的路径放在上面了啊:

API_KEY = open(r"C:\Users\chenh\Desktop\FlightTicket-master2\FlightTicket-master\API_KEY").readline().strip("\n")
if not API_KEY:
    raise Exception("You need to fill in the API_KEY in the directory.")

这你得问idocx哥,貌似是他更新的版本带的?

貌似你得先注册 ifttt.com ,拿到key,他参照了

@physixfan 是时候开一个技术版(刷题)了 :joy: :rofl:

卧槽,这个必须点赞!

各位,google flights覆盖哪些航空公司呢?大韩,釜山,深圳等等的票也会出现吗?

回答自己问题… 釜山官网上能够看到7月17日的首尔飞深圳航班,可是google flights上没有…

貌似一些小公司的航班Google flight上都没有