Selenium模拟登陆爬虫

技术路线:selenium+Chrome

注意事项:

1、chrome版本(chrome://version/)和chromedriver版本的匹配。
# 版本匹配参考https://blog.csdn.net/huilan_same/article/details/51896672

2、windows:下载驱动后复制到路径D:\Anaconda\Library\bin,官方IDLE就复制到D:\Python,这样就不用设置环境变量了 ,也不用在driver = webdriver.Chrome() 的 "()" 中输入路径

# selenium自动化操作

'''
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--headless")       # define headless
driver = webdriver.Chrome(chrome_options=chrome_options)
上面的一系列操作是为了不让浏览器弹出窗口
'''

from selenium import webdriver
from bs4 import BeautifulSoup
driver=webdriver.Chrome()   # 打开chrome浏览器

#打开小米登陆界面
driver.get("https://account.xiaomi.com/pass/serviceLogin?callback=https%3A%2F%2Forder.mi.com%2Flogin%2Fcallback%3Ffollowup%3Dhttps%253A%252F%252Fwww.mi.com%252Fredminote7%252F%26sign%3DYWM1Y2MyNjllNzA2NWNkMjJjOTg3NWQyMmI5YTBjMGZjYmRlNWNjMQ%2C%2C&sid=mi_eshop&_bannerBiz=mistore&_qrsize=180")

#输入小米账号
driver.find_element_by_xpath('//*[@id="username"]').clear()
driver.find_element_by_xpath('//*[@id="username"]').send_keys("************")
# 输入小米密码
driver.find_element_by_xpath('//*[@id="pwd"]').clear()
driver.find_element_by_xpath('//*[@id="pwd"]').send_keys("**************")


driver.find_element_by_xpath('//*[@id="login-button"]').click()


 

你可能感兴趣的:(python)