selenium模拟登录QQ空间,未解决验证码问题,但是可以在下方设置time.sleep(),时间长一点手动操作验证码,实现成功登录:
#coding:utf-8 import selenium import selenium.webdriver import time #QQ空间 现在登录需要验证码,可以模拟浏览器输入用户名和密码,验证码还未解决,但是可以在下方设置time.sleep(),时间长一点手动操作验证码,实现成功登录 driver = selenium.webdriver.Chrome() driver.get("https://qzone.qq.com/") time.sleep(3) driver.switch_to_frame("login_frame") elem=driver.find_element_by_id("switcher_plogin") elem.click() time.sleep(3) user=driver.find_element_by_id("u") password=driver.find_element_by_id("p") loginbtn=driver.find_element_by_id("login_button") user.send_keys("用户名") password.send_keys("密码") loginbtn.click() time.sleep(6) print( driver.title )#标题 #print( driver.page_source->lxml,re,bs4 ) #print( driver.find_element_by_class_name("title-text ui-mr5").text ) #print( driver.find_element_by_xpath("//span[@class="title-text ui-mr5"]").text ) print( driver.find_element_by_id("QZ_Space_Desc").text ) # .text 获取标签之间的内容 #print( driver.find_element_by_xpath("//span[@class="user-name textoverflow"]").text ) print( driver.find_element_by_id("QM_OwnerInfo_Icon").get_attribute("src") ) #text标签之间的东西 get_attribute("src")标签之内的东西 get_attribute 属性 time.sleep(40) print(driver.page_source) time.sleep(20) driver.close()