嗨害大家好鸭,我是小熊猫❤
不知道大家都考完驾照没?
这个驾照不管大家有没有,我相信大家都是这个:
朋友最近在考驾照,快考科一了…
我微微一笑当场给他整个活~
用Python整了几十行代码,给朋友实现一下自动答题~
我说你什么时候答题这么快,我就给你买个车!
嘿嘿,悄悄告诉你们,那是不可能的,不信你们看案例演示!
案例效果演示
原速未加速
代码展示
代码仅做展示
网址我屏蔽了,不然系统不给过~
模块
import requests
import parsel
from selenium import webdriver
发送请求
获取答案链接
def get_answer_url(html_url):
"""
:param html_url:
:return:
"""
html_data = get_response(html_url).text
selector = parsel.Selector(html_data)
answer_url_id = selector.css('.Content li::attr(c)').getall()
answer_url_list = [f'https://地址我屏蔽了,不然不给过/Post/{i}.htm' for i in answer_url_id]
return answer_url_list
获取答案
def get_answer_result(answer_url):
"""
:param answer_url:
:return:
"""
answer_data = get_response(html_url=answer_url).text
selector = parsel.Selector(answer_data)
question = selector.css('#question a::text').get()
answer = selector.css('#question h1 u::text').get()
if answer == '对':
answer = '正确'
elif answer == '错':
answer = '错误'
answer_dict = {
'问题': question,
'答案': answer
}
return answer_dict
获取所有问题以及答案
def get_all_answer(answer_url_list):
"""
:param link:
:return:
"""
page = 1
for answer_url, li in zip(answer_url_list, lis):
answer_dict = get_answer_result(answer_url)
bs = li.find_elements_by_css_selector('b')
num = 1
for b in bs:
choose = b.text
if len(choose) > 2:
choose = choose[0]
print(choose, answer_dict['答案'])
if choose in answer_dict['答案']:
driver.find_element_by_css_selector(f'#LI{page} b:nth-child({num+2})').click()
print('点击了')
else:
print('没有点击')
num += 1
page += 1
print(answer_dict)
今天的文章就到这里啦~
我是小熊猫,咱下篇文章再见啦(✿◡‿◡)
完整源代码下方名片获取哈~
最后给大家推荐一套Python视频:
拜托三连啦!【只用12小时,副业月入过万】python船新版本,入门可刑