📜  在Python中使用Selenium登录 Booking.com

📅  最后修改于: 2022-05-13 01:55:06.550000             🧑  作者: Mango

在Python中使用Selenium登录 Booking.com

在本文中,我们将学习一个简单的如何通过selenium登录Booking.com 。 Selenium是一个免费工具,用于跨特殊浏览器进行自动试用。

要求:

  • 您需要安装chromedriver并设置路径。点击这里下载。
  • Selenium是一个强大的工具,用于通过程序控制 Web 浏览器并执行浏览器自动化。它适用于所有浏览器,适用于所有主要操作系统,其脚本是用各种语言编写的,即 Python Java C#,我们将使用Python。

以下是步骤:

  • 首先,访问booking.com 网站。
  • 然后通过紧急ctrl + shift + i单击调查元素或进入浏览器设置并手动单击调查详细信息。
  • 然后导航填写电子邮件的框,然后复制x_path。

  • 然后导航下一个按钮并复制x_path

  • 然后导航 Password 然后复制x_path

  • 然后导航登录按钮,然后复制x_path

下面是实现:

Python3
# import required modules
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
  
# create instance of Chrome webdriver
driver = webdriver.Chrome()
driver.get("https://account.booking.com/sign-in?op_token=EgVvYXV0aCLdAgoUdk8xS2Jsazd4WDl0VW4yY3BaTFMSCWF1dGhvcml6ZRo1aHR0cHM6Ly9zZWN1cmUuYm9va2luZy5jb20vbG9naW4uaHRtbD9vcD1vYXV0aF9yZXR1cm4q_AFVcm9CSnFTUk5fY0p6TzJ2d0VuTzdycl92NzBncExyTEZ1TDc0Z2RlNlB2Tnc5T1FscEFISEI5MlpWVGZpNFd1eWplaDE0dm50S0Q5aHBXM3ladWdpLXY0SEZoLVFhRDdSbGk5dkRzSmN0MmE4ZXNpZEU1VHo0WkRyTDB3M3Y5Um9UNEU3dUh1SzMxZXNfTmM3Q2l4NWtNUkxpRFk0cnhEVVBaRXo5enJXV2psdVBnNHBpUlBNaUh4LUJzRTNSWVA1Z19WVWRSSHdOQTVzcWhGVGkzSDlET013dUJFWHY4dThsQjE4Z3BfdUJJLUtGaDQxSUgzcGYxWGx1TkVCBGNvZGUqFgiOyBIwwaf46Ii8JDoAQgBYgd3j_AU")
  
# find the element where we have to
# enter the xpath
# fill the  email
driver.find_element_by_xpath('//*[@id="username"]').send_keys('xxxxxx.com')
  
# click on next button
driver.find_element_by_xpath(
    '//*[@id="root"]/div/div[2]/div[1]/div/div/div/div/div/div/form/div[3]/button/span').click()
  
# find the element where we have to
# enter the xpath
# fill the password
driver.find_element_by_xpath('//*[@id="password"]').send_keys('Praxxxxx')
  
# find the element Sign in
# request using xpath
# clicking on that element
driver.find_element_by_xpath(
    '//*[@id="root"]/div/div[2]/div[1]/div/div/div/div/div/div/form/button/span').click()


输出: