使用selenium進行微博的模擬登陸
阿新 • • 發佈:2019-02-06
不多說,直接上程式碼了
# -*- coding:utf-8 -*- from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support.wait import WebDriverWait import time driver = webdriver.Firefox() driver.get("https://weibo.com/") wait = WebDriverWait(driver, 1000) load = (By.CSS_SELECTOR,"html body.FRAME_login div.B_unlog div.WB_miniblog div.WB_miniblog_fb div#plc_frame.WB_main.clearfix div.WB_frame div#plc_main div#plc_unlogin_home_main div.WB_main_r div#pl_unlogin_home_login div div.UG_box div.W_unlogin_v4 div#pl_login_form.login_box div.login_innerwrap div.W_login_form div.info_list.auto_login.clearfix") wait.until(EC.presence_of_element_located(load)) name = driver.find_element_by_xpath('//*[@id="loginname"]').send_keys('15210358424') # node-type="password" password = driver.find_element_by_css_selector(".input_wrap input[node-type='password']").click() # print password driver.find_element_by_css_selector('.input_wrap input[name="password"]').click() driver.find_element_by_css_selector('.input_wrap.W_input_focus input[node-type="password"]').send_keys('1995964huyu') button = driver.find_element_by_css_selector(".info_list.login_btn a[node-type='submitBtn']").click() print button