日韩性视频-久久久蜜桃-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行代码中的廉价航班的全部內容,希望文章能夠幫你解決所遇到的問題。

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

    主站蜘蛛池模板: 韩国女主播av | 中文字幕第27页 | 打屁股av| 99热日韩 | 爱爱福利社| 亚洲hh | av不卡在线看 | 草草浮力影院 | 国产男女猛烈无遮挡免费观看网站 | 永久免费汤不热视频 | 狠狠地日| 国产一区精品无码 | 国产女人18毛片水18精品 | 亚洲成人久久久 | 女人被狂躁c到高潮喷水电影 | 超碰综合网 | 视频国产一区 | 天干夜天干天天天爽视频 | 国产精品无码人妻一区二区在线 | 国产一区二区视频免费在线观看 | www在线观看免费视频 | 国产一区二区在线看 | 国产欧美一区二区三区精华液好吗 | 怎么可能高潮了就结束漫画 | 一区二区日韩电影 | 日韩一二三四区 | 国产美女福利视频 | 日韩av成人在线观看 | 蜜桃视频久久一区免费观看入口 | 日本精品网站 | 日b在线观看 | 男男h黄动漫啪啪无遮挡软件 | 国产娇小hdxxxx乱 | 钰慧的mv视频在线观看 | 狠狠的干狠狠的操 | 爱爱免费视频网站 | 在线视频福利 | 92av视频 | 亚洲国产精品久久AV | 性高潮久久久久久 | 男女污污视频在线观看 | 91大神一区二区 | 日韩中文一区二区 | 精品人妻一区二区三区日产 | 风间由美在线观看 | 中文字幕av高清片 | 毛片毛片 | 琪琪色影音先锋 | 第一章豪妇荡乳黄淑珍 | 日韩欧美一区二区三区在线 | 国产东北真实交换多p免视频 | 激情小说av| 韩国一级淫一片免费放 | 亚洲欧美一区在线 | 91国产高清 | 日韩欧美123 | 久操成人 | 蜜桃91精品入口 | 婷婷91| 色七七在线 | 古代黄色片 | 久久免费视频一区二区 | 国产精品一线二线 | 999精品在线 | 国产绳艺sm调教室论坛 | 国产中文欧美日韩在线 | 亚洲国产成人精品女人久久 | 天天插天天 | 天天狠狠干 | 一区二区在线看 | 丝袜人妻一区二区三区 | 在线免费观看一区二区三区 | 国产美女视频免费观看下载软件 | 国产chinese中国hdxxxx | 麻豆乱码国产一区二区三区 | 国产精品久久久久久在线观看 | 一级肉体全黄毛片 | 超碰c | 欧美激情亚洲激情 | 日本免费高清 | 日韩黄色片网站 | 萌白酱在线观看 | 亚洲影视一区二区 | 伊人狼人久久 | 美女二区 | 欧美体内she精高潮 日韩一区免费 | 天天躁狠狠躁 | 久视频在线观看 | 少妇在线视频 | 国产一区二区网 | 精品欧美色视频网站在线观看 | 一级美女黄色片 | av88av| 日本xxxx裸体xxxx | 亚洲国产精品成人综合 | 粉色午夜视频 | 特级毛片a| 国产精品久久无码 | 天天操中文字幕 |