|

楼主 |
发表于 2022-12-16 15:07:32
|
显示全部楼层
from selenium import webdriver
import time
import os
#打开浏览器驱动
driver_path=os.path.join(os.getcwd()+'\\msedgedriver.exe')
print(driver_path)
'''driver_path1="r"+"'"+driver_path+"'"
print(driver_path1)'''
wd = webdriver.Edge(driver_path)
wd.get('https://www.hwinfo.com/')#进入hwinfo官网
time.sleep(3)#让网页完整加载
wd.find_element_by_xpath('/html/body/article/div[1]/div[1]/div/a').click()#点击下载
wd.maximize_window()#窗口最大化
mainWindow = wd.current_window_handle#保存当前页面handle值便于返回
wd.switch_to.window(mainWindow)#返回原来窗口以防误触
wd.switch_to.frame('aswift_2')#去除广告 就是这里
wd.switch_to.frame('ad_iframe')
#wd.switch_to.frame('ad_position_box')
wd.find_element_by_id('dismiss-button').click()
time.sleep(3)#让网页完整加载
不知道行不行在前面加上一个保存handle的语句 |
|