日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

廉价raid_如何查找80行代码中的廉价航班

發布時間:2023/12/15 编程问答 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 廉价raid_如何查找80行代码中的廉价航班 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

廉價raid

Since travelling has become practically impossible, I decided to think about how I could start preparing for my next trip. That’s right, I got travel on my mind.

由于實際上已經不可能旅行了,所以我決定考慮如何才能為下次旅行做準備。 沒錯,我想到了旅行。

As most people know, plane tickets prices vary a lot. That is because airline companies use yield management, a pricing strategy that aims to anticipate consumer behaviour to maximize profits.

眾所周知,機票價格相差很大。 那是因為航空公司使用收益管理,這是一種定價策略,旨在預期消費者的行為以最大化利潤。

For instance, with the code I will present below, I looked at a plane ticket Montreal-Oslo 48 times per day for 2 days. The price varied between 891$ and 1298$ (all data was scrapped from Kayak, right here). Same dates, same destinations, a huge difference in prices.

例如,使用下面將要顯示的代碼,我每天兩次瀏覽蒙特利爾-奧斯陸飛機票,共2天。 價格在891美元和1298美元之間變化 (所有數據都是從Kayak 此處的廢棄的)。 相同的日期,相同的目的地,價格差異巨大。

W

w ^

Here is the code.

這是代碼。

包和參數 (Packages and parameters)

Let’s begin by importing the necessary packages:

讓我們從導入必要的包開始:

# import librariesfrom bs4 import BeautifulSoup
from selenium import webdriver
import pandas as pd
import datetime, re, time, itertools, smtplib, ssl
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart

Then, we define the parameters needed for the code to work:

然后,我們定義代碼運行所需的參數:

#Define parametersstart_date = datetime.datetime(2020,9,13)
days_range = 2
trip_length, min_length, max_length = 7, 6, 12
price_goal = 900
cities = 'YMQ-OSL'
  • Start_date: the earliest date for the flight to take off.

    Start_date :航班起飛的最早日期。

  • days_range: The maximum number of days away from the start_date to depart. Basically, what is the latest the trip could start (so September 15th here).

    days_range :距出發start_date要離開的最大天數。 基本上,這次旅行可以開始的最新時間是什么(所以這里是9月15日)。

  • trip_length, min_length, max_length : the desired trip length, as well as the minimum and maximum acceptable lengths. Can be equal to trip_length.

    trip_length, min_length, max_length :所需的行程長度以及最小和最大可接受長度。 可以等于trip_length 。

  • price_goal: Price at which you want to receive an email alert.

    price_goal :您要接收電子郵件警報的價格。

  • cities: The cities for the departure and arrival. In order to find the correct abbreviation, look at the URL when you search for flights on the website.

    cities :出發和到達的城市。 為了找到正確的縮寫,請在網站上搜索航班時查看URL。

創建日期組合 (Creating dates combinations)

Now that all the parameters are defined, here is how to create all the possible departing/returning dates combinations for the trip.

既然已經定義了所有參數,下面就是如何為行程創建所有可能的出發/回程日期組合。

Indeed, it’s possible that you have flexible dates, both in departure/return or in lenght of the trip. The following code will generate, based on the parameters defined earlier, all the possible travelling dates.

確實,您可能有靈活的日期,無論是出發/回程還是行程時間。 以下代碼將根據先前定義的參數生成所有可能的旅行日期。

First, I used the itertools library to generate all possible combinations of dates.

首先,我使用了itertools庫來生成所有可能的日期組合。

Then, the following loop allows us to get rid of all the dates that don’t respect the conditions (minimum/maximum length of the trip) or incoherent dates (return before departure date).

然后,下面的循環使我們能夠擺脫所有不符合條件的日期(行程的最小/最大長度)或不連貫的日期(出發日期之前返回)。

Finally, the following lines of code clean the dates to make them usable for the loop that follows.

最后,以下代碼行清除了日期,以使其可用于隨后的循環。

#Cleaning dates to make them usable in loopfor i in range(len(departing)):
departing[i]=re.sub(' 00:00:00', '', departing[i])
returning[i]=re.sub(' 00:00:00', '', returning[i])

收集數據并接收警報 (Scraping the data and receiving alerts)

Now, on to the real stuff. Here is the algorithm used to find the best flights and ensure that you receive an alert when the prices are low enough.

現在,介紹真正的東西。 這是用于查找最佳航班并確保您在價格足夠低時收到警報的算法。

  • Insert in the URL the cities and dates

    在網址中插入城市和日期
  • Get the price for the best flight proposed by Kayak using Selenium and Beautiful Soup

    獲取皮劃艇使用Selenium和美麗湯建議的最佳航班的價格
  • If a price is found, keep it, if not, return “no flights found” (try-expect loop)

    如果找到價格,則保留該價格,否則,返回“未找到航班”(try-expect循環)
  • If the price found is inferior to the price_goal parameter, send an email alert, containing the URL where the price was found.

    如果找到的價格低于price_goal參數,請發送電子郵件警報,其中包含找到價格的URL。

  • Here is the full code.

    這是完整的代碼。

    There are 3 things I want to mention here. First, don’t forget to download a chrome driver (and adjust the executable path in line 6) to use Selenium.

    我想在這里提到三件事。 首先,不要忘記下載chrome驅動程序(并在第6行中調整可執行路徑)以使用Selenium。

    Second, don’t forget to update the sender, password and receiver parameters. Those specify what address is sending the email and what address will be receiving it. You could also change the email content (the subject or the body) if you want.

    其次,不要忘記更新發送者,密碼和接收者參數。 那些指定發送電子郵件的地址和接收電子郵件的地址。 如果需要,您還可以更改電子郵件內容(主題或正文)。

    Third, the code is currently set up for a Gmail address sender. For any other type of address, the port (line 22) and the stmp.gmail.com (line 37) should be changed.

    第三,目前已為Gmail地址發件人設置了代碼。 對于任何其他類型的地址,應更改端口(第22行)和stmp.gmail.com (第37行)。

    Here is what the email alert received should look like:

    收到的電子郵件警報如下所示:

    使用任務計劃程序 (Using the Task Scheduler)

    All this is a good start but it would be a waste of time to constantly run the code manually until a good deal is found. Might as well look for deals on Kayak manually, like anybody would.

    所有這一切都是一個好的開始,但是要不斷地手動運行代碼直到找到大量交易,這將浪費時間。 像任何人一樣,還可以手動在Kayak上尋找交易。

    Thankfully, task schedulers exist. The idea is simple. You can schedule for your code to run N amount of times per day for however long you want. You can even have it work when the computer is sleeping (not turned off however).

    幸運的是,任務計劃程序存在。 這個想法很簡單。 您可以計劃每天將代碼運行N次,無論時間長短。 您甚至可以在計算機處于Hibernate狀態時使它正常工作(但是未關閉)。

    For a tutorial on how to setup the Windows Task Scheduler with a python script, go here. Using this tool can be super useful for many situations and I highly recommend you learn to use it!

    有關如何使用python腳本設置Windows Task Scheduler的教程,請轉到此處 。 在許多情況下使用此工具都非常有用,我強烈建議您學習使用它!

    You can now let your computer search for cheap flights while you sit back and have a beer. You just saved both time and money, all of it for free.

    現在,當您坐下來喝啤酒時,可以讓計算機搜索廉價航班。 您只是節省了時間和金錢,所有這些都是免費的。

    Thanks a lot for reading!

    非常感謝您的閱讀!

    Full code available here.

    完整的代碼在這里 。

    翻譯自: https://towardsdatascience.com/how-to-find-cheap-flights-in-80-lines-of-code-ba4f492587db

    廉價raid

    總結

    以上是生活随笔為你收集整理的廉价raid_如何查找80行代码中的廉价航班的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

    主站蜘蛛池模板: 欧美极品喷水 | 中文字幕第7页 | 欧美综合亚洲图片综合区 | 亚洲精品黄 | 国产丝袜美女 | 国产精品视频久久久 | 小sao货水好多真紧h无码视频 | 日韩精品国产一区二区 | 图书馆的女友动漫在线观看 | 亚洲精品香蕉 | 激情开心站 | 日本韩国欧美一区二区 | 第一色影院 | 超碰一区二区 | 麻豆成人av| 久久久久亚洲无码 | 亚洲少妇一区二区三区 | 国产三级国产精品国产专区50 | 亚洲精品四区 | 九一国产在线观看 | av中文一区 | 在线播放亚洲 | 亚洲操操 | 伊人久久久久久久久久 | 久久久久久久久久国产精品 | 无码人妻精品一区二区蜜桃视频 | 色妞网站 | 91精品国产成人观看 | 91成人看片 | 久久综合网址 | 色哟哟黄色 | 已满十八岁免费观看全集动漫 | 女性毛片 | 免费人成年激情视频在线观看 | 日本黄色免费视频 | 色婷婷狠狠 | 免费观看黄网站 | 中文字幕电影一区 | 国产色婷婷一区二区三区竹菊影视 | 国产精品老女人 | 久久激情影院 | 精品一区二区三区三区 | 理论片久久 | 日韩精品福利 | 337p日本欧洲亚洲鲁鲁 | 久久天天躁狠狠躁夜夜躁 | 亚洲激情网| 欧美混交群体交 | av资源网址| 国产免费看黄 | 日本一级理论片在线大全 | 男插女av | 十大污网站 | 婷婷伊人综合 | 欧美破处大片 | 美女试爆场恐怖电影在线观看 | 色婷婷导航 | 北条麻妃久久 | 欧美日韩免费高清 | 99er久久 | 91性视频| 久久视频中文字幕 | 亚洲一区二区在线 | www,99| 欧美日韩视频在线观看一区 | 在线观看jizz | 精品丰满人妻无套内射 | 亚洲 精品 综合 精品 自拍 | 极品人妻一区二区 | 久久福利社 | 午夜免费片 | 亚洲国产乱 | 亚洲av综合av一区二区三区 | 精品99视频 | 日韩一二三四五区 | 日韩美女中文字幕 | 强行无套内谢大学生初次 | 国产精品久久久午夜夜伦鲁鲁 | 999久久 | 黄色一区二区三区四区 | 大香蕉毛片 | 亚洲伦理一区二区三区 | 久久免费观看视频 | 精品黑人一区二区三区久久 | 欧美天天搞 | 欧美一级黑人 | 亚洲av无码一区二区三区四区 | 热久久久久久久 | 亚洲特黄视频 | 五月婷婷在线观看视频 | 高潮一区二区三区 | 在线观看中文字幕2021 | 国产亚洲欧美日韩高清 | 中文字幕亚洲欧美日韩在线不卡 | 天堂在线视频免费观看 | 91久久精品美女高潮 | 久99精品 | 亚洲 国产 欧美 日韩 | 日韩精品国产一区二区 |