在打开所需的网址之前,我在chromedriver上安装了chrome扩展程序。 随着扩展程序的安装,它会打开一个提示“感谢您安装”的标签。
扩展网址:https://chrome.google.com/webstore/detail/buyhatke/jaehkpjddfdgiiefcnhahapilbejohhj?hl=en
我想关闭由扩展程序打开的标签页,因为它会不必要地加载数据。
代码段:
from selenium import webdriver
import time
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from bs4 import BeautifulSoup as soup
chrome_options = Options()
chrome_options.add_argument('load-
extension=C:\\Users\\SACHIN\\AppData\\Local\\Google\\Chrome\\User Data\\Default\\Extensions\\jaehkpjddfdgiiefcnhahapilbejohhj\\3.4.141_0')
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.implicitly_wait(30)
driver.get("https://paytm.com/shop/p/samsung-j3-pro-16-gb-black-MOBSAMSUNG-J3-PSTPL5914255C1B4E1C?src=grid&tracker=curated%7C%7Cmobile%20phones%7CCategory%20Grid%7C%2Fg%2Fmobile-accessories%2Fmobiles%2Fsmart-phones%7C66781%7C1%7C")
答案 0 :(得分:2)
您可以切换为标签
window_before = driver.window_handles[0] // May be 1 in your case
driver.switch_to_window(window_before)
并关闭驱动程序。
或发送Alt + Tab键并关闭标签