Saturday, November 6, 2021

selenium 5 booking bot 1

#logs
(venv) C:\Users\zchen\PycharmProjects\selenium>python run.py
start __init__.py

DevTools listening on ws://127.0.0.1:58774/devtools/browser/c93522ba-e462-4a03-aaa5-241da59d7535
https://www.booking.com is opened
exiting...
#Booking/booking.py

import Booking.constants as constants
import os
from selenium import webdriver

class Booking(webdriver.Chrome):
    def __init__(self, path=r"C:/Users/zchen/PycharmProjects/selenium"):
        self.driver_path = path
        os.environ['PATH'] += self.driver_path
        super(Booking, self).__init__()

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.quit()

    def open_page(self):
        self.get(constants.BASE_URL)
        print(constants.BASE_URL, 'is opened')

-----------------------
#run.py

from Booking.booking import Booking

with Booking() as bot:
    bot.open_page()
    print('exiting...')

-----------------
#Booking/__init__.py

print("start __init__.py")

-------------------
#Booking/constants.py

BASE_URL = "https://www.booking.com"

reference:

No comments:

Post a Comment