【发布时间】:2020-11-29 13:04:21
【问题描述】:
我一直在尝试使用 python selenium 自动化 facebook 搜索,但我不知道如何允许或阻止弹出窗口,我在下面提供了一张图片,这可能有助于您更好地理解问题
https://i.stack.imgur.com/V1ABR.png
这是代码,我不知道我导入了什么,但它仍然有效:-)
import time
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
driver = webdriver.Chrome()
facebook_URL = ('https://www.facebook.com/')
twitter_URL = ('https://www.twitter.com/')
def facebook():
driver.get(facebook_URL) # To open the browser and search for facebook
time.sleep(2)
# It finds the Input box for the email
emailFace = driver.find_element_by_xpath('//*[@id="email"]')
# This inputs the the text which we want to
emailFace.send_keys('hello@gmail.com')
passFace = driver.find_element_by_xpath('//*[@id="pass"]')
passFace.send_keys('check1234')
loginFace = driver.find_element_by_xpath('//*[@id="u_0_b"]')
loginFace.click()
def twitter():
driver.get(twitter_URL) # To open the browser and search for facebook
time.sleep(2)
logIn = driver.find_element_by_xpath(
'//*[@id="react-root"]/div/div/div/main/div/div/div/div[1]/div/a[2]')
logIn.click()
# It finds the Input box for the email
emailTwitt = driver.find_element_by_xpath(
'//*[@id="react-root"]/div/div/div[2]/main/div/div/div[1]/form/div/div[1]/label/div/div[2]/div/input')
# This inputs the the text which we want to
emailTwitt.send_keys('hello@gmail.com')
passTwitt = driver.find_element_by_xpath(
'//*[@id="react-root"]/div/div/div[2]/main/div/div/div[1]/form/div/div[2]/label/div/div[2]/div/input')
passTwitt.send_keys('check1234')
loginTwitt = driver.find_element_by_xpath(
'//*[@id="react-root"]/div/div/div[2]/main/div/div/div[1]/form/div/div[3]/div')
loginTwitt.click()
facebook()
【问题讨论】:
-
真的有用吗?
-
我还没试过,如果有效我会告诉你谢谢!
标签: python selenium selenium-webdriver