t淘宝登录后弹窗问题
鱼佬们看看 没反应VikingNine 发表于 2020-8-13 11:11
没反应
建议发完整代码 1q23w31 发表于 2020-8-13 12:32
建议发完整代码
from selenium import webdriver
import time
class loginclass:
def __init__(this):
# chrome_options 初始化选项
this.chrome_options = webdriver.ChromeOptions()
this.chrome_options.add_experimental_option("excludeSwitches", ['enable-automation'])
# 不加载图片,加快访问速度
# this.chrome_options.add_experimental_option("prefs", {"profile.managed_default_content_settings.images": 2})
# 关闭开发者模式
this.chrome_options.add_experimental_option("useAutomationExtension", False)
# 设置为开发者模式,避免被识别
# this.chrome_options.add_experimental_option('excludeSwitches', ['enable-automation'])
this.web_driver = webdriver.Chrome(r"D:\Users\Liht\PycharmProjects\taobao\taobao\chromedriver.exe",options=this.chrome_options)
# this.web_driver_wait = WebDriverWait(this.web_driver, 10 , 0.5)
# 通过浏览器的dev_tool在get页面钱将.webdriver属性改为"undefined"
this.web_driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
"source": """Object.defineProperty(navigator, 'webdriver', {get: () => undefined})""",
})
this.url = 'https://login.taobao.com/member/login.jhtml'
this.username = "."
this.password = "."
def get_login_cookie(this):
# this.chrome_options = webdriver.ChromeOptions()
# this.chrome_options.add_experimental_option("excludeSwitches", ['enable-automation'])
# this.chrome_options.add_experimental_option("prefs", {"profile.managed_default_content_settings.images": 2})
# # 关闭开发者模式
# this.chrome_options.add_experimental_option("useAutomationExtension", False)
# browser = webdriver.Chrome(r"D:\Users\Liht\PycharmProjects\taobao\taobao\chromedriver.exe", options=this.chrome_options)
# # 通过浏览器的dev_tool在get页面钱将.webdriver属性改为"undefined"
# browser.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
# "source": """Object.defineProperty(navigator, 'webdriver', {get: () => undefined})""",
# })
this.web_driver.get(this.url)
# browser.maximize_window()# 最大化
# 填写用户名密码
id = this.username
password = this.password
this.web_driver.find_element_by_xpath('//*[@id="fm-login-id"]').clear()
this.web_driver.find_element_by_xpath('//*[@id="fm-login-id"]').send_keys(id)
this.web_driver.find_element_by_xpath('//*[@id="fm-login-password"]').clear()
this.web_driver.find_element_by_xpath('//*[@id="fm-login-password"]').send_keys(password)
time.sleep(2)
# 登录 //*[@id="J_GetCode"]
this.web_driver.find_element_by_xpath('//*[@id="login-form"]/div/button').click()
# print('登录成功\n')
if this.is_element_exist("#J_GetCode"):
this.web_driver.find_element_by_xpath('//*[@id="J_GetCode"]').chick()
yzm = input("请输入手机验证码:")
this.web_driver.find_element_by_xpath('//*[@id="J_Phone_Checkcode"]').send_keys(yzm)
this.web_driver.find_element_by_xpath('//*[@id="submitBtn"]').chick()
#登录后弹框=》跳过
# if this.is_element_exist("/html/body/div/div/div/div/div"):
this.web_driver.find_element_by_xpath('/html/body/div/div/div/div/div').chick()
if this.is_element_exist("#container"):
this.web_driver.find_element_by_xpath('//*[@id="container"]/div/div/div/div/div/div/div/ul/li/a').click()
input("禁止跳出")
def is_element_exist(this,css):
s = this.web_driver.find_elements_by_css_selector(css_selector=css)
if len(s) == 0:
print("元素未找到:%s"%css )
return False
elif len(s) == 1:
return True
else:
print("找到%s个元素:%s"%(len(s),css))
return False
if __name__ == '__main__':
loginclass().get_login_cookie() <div class="indexnotice-step-1JI8T indexfooter-item-1lnBd">跳过</div>
body > div:nth-child(15) > div > div.indexnotice-body-5-O5b > div.indexnotice-footer-cRiPs > div.indexnotice-step-1JI8T.indexfooter-item-1lnBd
document.querySelector("body > div:nth-child(15) > div > div.indexnotice-body-5-O5b > div.indexnotice-footer-cRiPs > div.indexnotice-step-1JI8T.indexfooter-item-1lnBd")
--antd-wave-shadow-color: #1890ff;
font: 12px/1.5 tahoma,arial,'Hiragino Sans GB',"Microsoft Yahei",\5b8b\4f53,sans-serif;
-webkit-font-smoothing: antialiased!important;
font-family: tahoma, arial, "Hiragino Sans GB", "Microsoft Yahei", sans-serif;
font-size: 16px;
line-height: 1.28571;
text-align: right;
box-sizing: border-box;
user-select: none;
display: inline-block;
cursor: pointer;
color: #3386f1;
margin-left: 24px;
/html/body/div/div/div/div/div
这些是审查元素拷贝出来的不同类型
页:
[1]