爬虫-自动化完成上百题目
Posted Rgylin
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了爬虫-自动化完成上百题目相关的知识,希望对你有一定的参考价值。
背景:
为了帮舍友 完成某个任务,首先这个任务是这样的
简单说一下就是有好多人 每人呢有好多套题,本身是有答案的,我们要做的就是完成这上百套题.
首先题目是这样的 有单选有多选有判断
截一小段来看, 自动化yyds
这里拿单选来说
1、(单选题)B村村长金某某,群众基础非常好,在村民中威信很高。在B村委会换届投票选举过程中,为稳妥当选村长,金某某采用贿赂选民、请选民吃喝等手段让选民为其投票,最终当选村民委员会主任。下列表述正确的是()。
A.金某某的行为侵犯了本村选民自由行使选举权和被选举权
B.金某某的行为构成破坏选举罪
C.选举权和被选举权是人身自由权
D.金某某当选村长属于结果正义,选举有效
嗯,之前学过python 爬虫 那正好可以活学活用了
复习了一下 写了一个半自动化脚本 就是 还得需要点第几套 ,手动提交
还需要一个隐性等待
这里时间紧迫 过几天会再补充上
先用着
> 这里cookie 为了安全就删了 大家用的话需要大家自己弄cookie
注释中有获取的代码 ![请添加图片描述](https://img-blog.csdnimg.cn/0dcfaaef702c4fe98e6ec40adce730c5.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAUmd5bGlu,size_20,color_FFFFFF,t_70,g_se,x_16)
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import time
diver=webdriver.Chrome(executable_path="D:\\Chromdriver\\chromedriver_win32\\chromedriver2.exe")
diver.get('http://www.faxuanyun.com')
# time.sleep(2)
# diver.find_element_by_id('userAccount').send_keys('')
# diver.find_element_by_id('userPassword').send_keys()
#
# diver.implicitly_wait(30)
# time.sleep(7)
# diver.find_element_by_class_name('inpLogin').click()
# time.sleep(2)
# print(diver.get_cookies())
# diver.find_element_by_id('userPassword').send_keys('')
# diver.find_element_by_id('confPwd').send_keys('')
cookiie=[{'domain': 'www.faxuanyun.com', 'httpOnly': False, 'name': 'userTypeFog', 'path': '/', 'secure': False, 'value': '%221%22'}, {'domain': 'www.faxuanyun.com', 'httpOnly': False, 'name': 'passwordLevel', 'path': '/', 'secure': False, 'value': '1'}, {'domain': 'www.faxuanyun.com', 'expiry': 1636041599, 'httpOnly': False, 'name': 'loginUser', 'path': '/', 'secure': False, 'value': '%7B%22userAccount%22%3A%22370903008%2C%22roleId%22%3A%227%22%2C%22dom70000%22%2C%22id%22%3A%2235371722%22%2C%22sid%22%3A%22a78c20b879404146a60ce1e55ad11188%22%2C%22politicsCode%22%3A%22p00%22%2C%22onlineTime%22%3A1636014282000%7D'}, {'domain': 'www.faxuanyun.com', 'httpOnly': False, 'name': '_qddab', 'path': '/', 'secure': F1636016084, 'httpOnly': False, 'name': '_qdda', 'path': '/', 'secure': False, 'value': '3-1.1'}, {'domain': '.faxuanyun.com', 'httpOnly': False, 'name': 'rid', 'path': '/', 'secure': False, 'value': '9bb636d3d539c04b175e4f7aa26d810c'}, {'domain': 'www.faxuanyun.com', 'httpOnly': False, 'name': 'bindType', 'path': '/', 'secure': False, 'value': '1'}, {'domain': '.faxuanyun.com', 'expiry': 1667550284, 'httpOnly': False, 'name': '_qddaz', 'path': '/', 'secure': False, 'value': 'QD.791236014271840'}, {'domain': '.faxuanyun.com', 'expiry': 1667550271, 'httpOnly': Fayun.com'}, {'domain': 'www.faxuanyun.com', 'expiry': 1636041599, 'httpOnly': False, 'name': 'area', 'path': '/', 'secure': False, 'value': '%22000000%22'}, {'domain': '.www.faxuanyun.com', 'httpOnly': False, 'name': 'Hm_lpvt_183898d755583f6b54c8491f9c451ef5', 'path': '/', 'secure': False, 'value': '163601'httpOnly': False, 'name': 'RmbUser', 'path': '/', 'secure': False, 'value': '%7B%22RmbUser%22%3Afalse%2C%22userAccount%22%3A%223709030080066%22%2C%22userPassword%22%3A%22888888%22%7D'}]
for item in cookiie:
diver.add_cookie(item)
time.sleep(2)
#diver.get('http://www.faxuanyun.com/sps/exercises/t/exercies_3_t.html?id=5191&paperName=%E6%B7%84%E5%8D%9A%E5%B8%82%E6%B3%95%E5%BE%8B%E6%98%8E%E7%99%BD%E4%BA%BA%E6%B3%95%E6%B2%BB%E5%B8%A6%E5%A4%B4%E4%BA%BA%20%E4%B9%A0%E8%BF%91%E5%B9%B3%E6%B3%95%E6%B2%BB%E6%80%9D%E6%83%B3%E5%AD%A6%E4%B9%A0%E4%B8%93%E9%A2%98&status=0&loginUserAccount=3709030080066&courseId=4427')
diver.get('http://www.faxuanyun.com/sps/exercises/t/exercies_3_t.html?id=5192&paperName=%E6%B7%84%E5%8D%9A%E5%B8%82%E6%B3%95%E5%BE%8B%E6%98%8E%E7%99%BD%E4%BA%BA%E6%B3%95%E6%B2%BB%E5%B8%A6%E5%A4%B4%E4%BA%BA%20%E5%AE%AA%E6%B3%95%E5%AD%A6%E4%B9%A0%E4%B8%93%E9%A2%98&status=0&loginUserAccount=3709030080065&courseId=4428')
diver.maximize_window()
diver.refresh()
#第一套题答案
answer_1_1=['A','A','B','C','A','A','B','B','D','B']
answer_1_2=['ABD','AC','ABCD','AD','AC']
answer_1_3=['B','B','A','B','A']
#第二套答案
# diver.find_element_by_id('userPassword').send_keys('zmh123456')
# diver.find_element_by_id('confPwd').send_keys('zmh123456')
#
# diver.find_element_by_id('nextbtnForPwd').click()
# time.sleep(2)
# diver.find_element_by_id('ignore').click()
# time.sleep(2)
# diver.find_element_by_id('popalertConfirm').click()
time.sleep(2)
print('12')
for i in range(10):
diver.find_element_by_xpath("//div[@id='timucontent']//input[@type='radio'][@value='{0}']".format(answer_1_1[i])).click()
time.sleep(1)
diver.find_element_by_xpath("//a[@οnclick='sps.next()']").click()
time.sleep(1)
for i in range(0,5):
for j in answer_1_2[i]:
diver.find_element_by_xpath("//div[@id='timucontent']//input[@type='checkbox'][@value='{0}']".format(j)).click()
time.sleep(1)
diver.find_element_by_xpath("//a[@οnclick='sps.next()']").click()
time.sleep(1)
for i in range(0,5):
diver.find_element_by_xpath("//div[@id='timucontent']//input[@type='radio'][@value='{0}']".format(answer_1_3[i])).click()
time.sleep(1)
diver.find_element_by_xpath("//a[@οnclick='sps.next()']").click()
time.sleep(1)
time.sleep(1)
diver.find_element_by_xpath("//div[@class='clear']//a[@href='javascript:sps.myCommit();']").click()
升级
我们观察每个url特征 发现只有标题, 还有题目的序号有变化
比如这里
不同账号比较这个urlencode 可以解码解码则可以发现就是标题在发生变化 那末在人数折磨多的情况下我们则可以用lie表进行存储到时候直接调用即可
?id=5191&paperName=%E6%B7%84%E5%8D%9A%E5%B8%82%E6%B3%95%E5%BE%8B%E6%98%8E%E7%99%BD%E4%BA%BA%E6%B3%95%E6%B2%BB%E5%B8%A6%E5%A4%B4%E4%BA%BA%20%E4%B9%A0%E8%BF%91%E5%B9%B3%E6%B3%95%E6%B2%BB%E6%80%9D%E6%83%B3%E5%AD%A6%E4%B9%A0%E4%B8%93%E9%A2%98&status=0&loginUserAccount=3709030080071&courseId=4427
?id=5192&paperName=%E6%B7%84%E5%8D%9A%E5%B8%82%E6%B3%95%E5%BE%8B%E6%98%8E%E7%99%BD%E4%BA%BA%E6%B3%95%E6%B2%BB%E5%B8%A6%E5%A4%B4%E4%BA%BA%20%E6%B0%91%E6%B3%95%E5%85%B8%E5%AD%A6%E4%B9%A0%E4%B8%93%E9%A2%98&status=0&loginUserAccount=3709030080071&courseId=4429
同一个账号比较再观察一下其他变化的地方发现courseId 和 id 值发生变化 而且长度是8 那末我们 遍历即可
?id=5191&paperName=%E6%B7%84%E5%8D%9A%E5%B8%82%E6%B3%95%E5%BE%8B%E6%98%8E%E7%99%BD%E4%BA%BA%E6%B3%95%E6%B2%BB%E5%B8%A6%E5%A4%B4%E4%BA%BA%20%E4%B9%A0%E8%BF%91%E5%B9%B3%E6%B3%95%E6%B2%BB%E6%80%9D%E6%83%B3%E5%AD%A6%E4%B9%A0%E4%B8%93%E9%A2%98&status=0&loginUserAccount=3709030080071&courseId=4427
http://www.faxuanyun.com/sps/exercises/t/exercies_3_t.html?id=5192&paperName=%E6%B7%84%E5%8D%9A%E5%B8%82%E6%B3%95%E5%BE%8B%E6%98%8E%E7%99%BD%E4%BA%BA%E6%B3%95%E6%B2%BB%E5%B8%A6%E5%A4%B4%E4%BA%BA%20%E6%B0%91%E6%B3%95%E5%85%B8%E5%AD%A6%E4%B9%A0%E4%B8%93%E9%A2%98&status=0&loginUserAccount=3709030080071&courseId=4429
#脚本如下
from selenium import webdriver
import time
diver=webdriver.Chrome(executable_path="D:\\Chromdriver\\chromedriver_win32\\chromedriver2.exe")
diver.get('http://www.faxuanyun.com')
time.sleep(2)
# diver.find_element_by_id('userAccount').send_keys()
# diver.find_element_by_id('userPassword').send_keys(8)
#
# #diver.implicitly_wait(30)
# time.sleep(7)
# diver.find_element_by_class_name('loginBtn').click()
# time.sleep(2)
# print(diver.get_cookies())
title=['%E6%B7%84%E5%8D%9A%E5%B8%82%E6%B3%95%E5%BE%8B%E6%98%8E%E7%99%BD%E4%BA%BA%E6%B3%95%E6%B2%BB%E5%B8%A6%E5%A4%B4%E4%BA%BA%20%E4%B9%A0%E8%BF%91%E5%B9%B3%E6%B3%95%E6%B2%BB%E6%80%9D%E6%83%B3%E5%AD%A6%E4%B9%A0%E4%B8%93%E9%A2%98','%E6%B7%84%E5%8D%9A%E5%B8%82%E6%B3%95%E5%BE%8B%E6%98%8E%E7%99%BD%E4%BA%BA%E6%B3%95%E6%B2%BB%E5%B8%A6%E5%A4%B4%E4%BA%BA%20%E5%AE%AA%E6%B3%95%E5%AD%A6%E4%B9%A0%E4%B8%93%E9%A2%98','%E6%B7%84%E5%8D%9A%E5%B8%82%E6%B3%95%E5%BE%8B%E6%98%8E%E7%99%BD%E4%BA%BA%E6%B3%95%E6%B2%BB%E5%B8%A6%E5%A4%B4%E4%BA%BA%20%E6%B0%91%E6%B3%95%E5%85%B8%E5%AD%A6%E4%B9%A0%E4%B8%93%E9%A2%98','%E6%B7%84%E5%8D%9A%E5%B8%82%E6%B3%95%E5%BE%8B%E6%98%8E%E7%99%BD%E4%BA%BA%E6%B3%95%E6%B2%BB%E5%B8%A6%E5%A4%B4%E4%BA%BA%20%E5%85%9A%E5%86%85%E6%B3%95%E8%A7%84%E5%AD%A6%E4%B9%A0%E4%B8%93%E9%A2%98','%E6%B7%84%E5%8D%9A%E5%B8%82%E6%B3%95%E5%BE%8B%E6%98%8E%E7%99%BD%E4%BA%BA%E6%B3%95%E6%B2%BB%E5%B8%A6%E5%A4%B4%E4%BA%BA%20%E7%96%AB%E6%83%85%E9%98%B2%E6%8E%A7%E5%AD%A6%E4%B9%A0%E4%B8%93%E9%A2%98','%E6%B7%84%E5%8D%9A%E5%B8%82%E6%B3%95%E5%BE%8B%E6%98%8E%E7%99%BD%E4%BA%BA%E6%B3%95%E6%B2%BB%E5%B8%A6%E5%A4%B4%E4%BA%BA%20%E5%88%91%E4%BA%8B%E6%B2%BB%E5%AE%89%E5%AD%A6%E4%B9%A0%E4%B8%93%E9%A2%98','%E6%B7%84%E5%8D%9A%E5%B8%82%E6%B3%95%E5%BE%8B%E6%98%8E%E7%99%BD%E4%BA%BA%E6%B3%95%E6%B2%BB%E5%B8%A6%E5%A4%B4%E4%BA%BA%20%E4%BF%A1%E8%AE%BF%E5%AD%A6%E4%B9%A0%E4%B8%93%E9%A2%98','%E6%B7%84%E5%8D%9A%E5%B8%82%E6%B3%95%E5%BE%8B%E6%98%8E%E7%99%BD%E4%BA%BA%E6%B3%95%E6%B2%BB%E5%B8%A6%E5%A4%B4%E4%BA%BA%20%E4%BA%BA%E6%B0%91%E8%B0%83%E8%A7%A3%E5%AD%A6%E4%B9%A0%E4%B8%93%E9%A2%98']
url_='http://www.faxuanyun.com/sps/exercises/t/exercies_3_t.html?id={0}&paperName={1}&status=0&loginUserAccount=3709030080077&courseId={2}'
cookiie=[{'domain': '.www.faxuanyun.com', 'httpOnly': False, 'name': 'Hm_lpvt_183898d755583f6b54c8491f9c451ef5', 'path': '/', 'secure': False, 'value': '1636032218'}, {'domain': '.www.faxuanyun.com', 'expiry': 1667568217, 'httpOnly': False, 'name': 'Hm_lvt_183898d755583f6b54c8491f9c451ef5', 'path': '/', 'secure': '/', 'secure': False, 'value': '%7B%22userAccount%22%3A%223709030080069%22%2C%22userName%22%3A%22%E5%BC%A0%E4%BC%A0%E6%B3%A2%22%2C%22uType%22%3A%221%22%2C%22roleId%22%3A%227%22%2C%22domainCode%22%3A%22100027008003008%22%2C%22rankId%22%3A%22241%22%2C%22lockFlag%22%3A%220%22%2C%22areaCode%22%3A%22370000%22%2C%22%2C%22onlineTime%22%3A1636032216000%7D'}, {'domain': 'www.faxuanyun.com', 'expiry': 1636637016, 'httpOnly': False, 'nam', 'httpOnly': False, 'name': 'labelType', 'path': '/', 'secure': False, 'value': '%221%22'}, {'domain': '.faxuanyun.com', 'httpOnly': False, 'name': 'fxInd', 'path': '/', 'secure': False, 'value': 'I'}, {'domain': 'www.faxuanyun.com206, 'httpOnly': False, 'name': '__root_domain_v', 'path': '/', 'secure': False, 'value': '.faxuanyun.com'}, {'domain': 'www.faxuanyun.com', 'expiry': 1636041599, 'httpOnly': False, 'name': 'area', 'path': '/', 'secure': False, 'value':main': '.faxuanyun.com', 'expiry': 1667568204, 'httpOnly': False, 'name': 'Hm_lvt_714af84c5240734e0f5aefd5e3b68647', 'path': '/', 'secure'alse, 'value': '1636032204'}, {'domain': '.faxuanyun.com', 'expiry': 1667568218, 'httpOnly': False, 'name': '_qddaz', 'path': '/', 'secure': lse, 'value': 'QD.467936032206022'}, {'domain': 'www.faxuanyun.com', 'httpOnly': False, 'name': 'passwordLevel', 'path': '/', 'secure': False, 'value': '1'}, {'domain': '.faxuanyun.com', 'httpOnly': False, 'nam'Hm_lpvt_714af84c5240734e0f5aefd5e3b68647', 'path': '/', 'secure': False, 'value': '1636032204'}, {'domain': ', {'domain': '.faxuanyun.com', 'httpOnly': False, 'name': 'rid', 'path': '/', 'secure': False, 'value': 'e0bc95ec1dd764775fb3d7861baa5776'}]
for i in range(8):
url=url_.format(5191+i,title[i],4427+i)
print(url)
for item in cookiie:
diver.add_cookie(item)
time.sleep(2)
diver.get(url)
#diver.maximize_window()
diver.refresh()
#第一套题答案
answer_1=[['A','A','B','C','A','A','B','B','D','B'],['ABD','AC','ABCD','AD','AC'],['B','B','A','B','A']]
#第二套答案
answer_2=[['A','B','B','D','C','C','B','A','A','A'],['CD','ACD','AC','BCD','ABCD'],['A','A','A','A','A']]
answer_3=[['C','B','D','C','D','A','A','B','A','D'],['ABD','ABCD','ABCD','AB','BC'],['A','B','A','B','B']]
answer_4=[['B','A','D','D','A','A','A','B','A','A'],['ABCD','ABCD','ABCD','ABCD','ABCD'],['A','A','A','B','A']]
answer_5=[['B','B','A','B','B','D','B','A','D','C'],['ABC','AB','ABD','ABCD','AB'],['B','B','A','A','A']]
answer_6=[['C','D','B','C','B','A','D','C','B','C'],['ABCD','ABD','ABD','ABCD','ABCD'],['A','B','A','B','A']]
answer_7=[['C','B','A','A','C','A','C','A','B','A'],['ACD','ABCD','ABCD','ABC','ABD'],['B','B','A','A','A']]
answer_8=[['A','B','B','B','C','B','D','D','D','B'],['ABCD','AB','CD','ACD','AC'],['A','B','B','A','A']]
answer=[]
answer.append(answer_1)
answer.append(answer_2)
answe以上是关于爬虫-自动化完成上百题目的主要内容,如果未能解决你的问题,请参考以下文章
[AndroidStudio]_[初级]_[配置自动完成的代码片段]
[AndroidStudio]_[初级]_[配置自动完成的代码片段]