本文共 1078 字,大约阅读时间需要 3 分钟。
# -*- coding: UTF-8 -*-from selenium import webdriverfrom bs4 import BeautifulSoupimport time#这里我已经下载了geckodriver放在火狐文件夹,如果放入所需要执行的Python脚本的所在处就不用写这个了myDriver = webdriver.Firefox(executable_path ='F:\setup place\Firefox\geckodriver.exe')myDriver.get('http://www.heibanke.com/accounts/login')time.sleep(3)myDriver.find_element_by_id('id_username').send_keys('test')myDriver.find_element_by_id('id_password').send_keys('test123')myDriver.find_element_by_id('id_submit').click()time.sleep(1)number = 0 #被重定向后我们就重新写入要进入的URLwhile number<31: myDriver.get('http://www.heibanke.com/lesson/crawler_ex02/') time.sleep(2) myDriver.find_element_by_name('username').send_keys('test') myDriver.find_element_by_name('password').send_keys(str(number)) myDriver.find_element_by_id('id_submit').click() time.sleep(2) html = myDriver.page_source bs_obj = BeautifulSoup(html,"html.parser") print bs_obj.h3 if bs_obj.text.find(u'密码错误')>0: number = number + 1 print number else: print bs_obj.text breaktime.sleep(2)myDriver.close()复制代码
转载地址:http://dwgfx.baihongyu.com/