python爬虫selenium自动化-实现科目一自动答题
  WIU1Qlm7CwPb 2023年11月02日 88 0

通过selenium模块

实现驾驶员考试网站的科目一的自动考试答题

公众号回复 自动答题 获取源代码


打开这个网站

python爬虫selenium自动化-实现科目一自动答题_HTML

然后打开开发者模式,找到这些一个一个的题,每个li标签对应一个题,每个li标签上都有一个c属性

python爬虫selenium自动化-实现科目一自动答题_公众号_02


然后打开这个网址,这个网址存放着该题的答案,这个url后面接的是刚才的c属性值,对应着该题的答案

python爬虫selenium自动化-实现科目一自动答题_html_03

写代码,导入selenium包,导入webdrive模块

打开网站

python爬虫selenium自动化-实现科目一自动答题_html_04

获取c属性,打开存放答案的地址获取答案

while a<=100:
    # 获取答案网页地址,拼接答案网页地址
    d = driver.find_element(By.XPATH,f'.//ul[@class="Content"]/li[{a}]').get_attribute('c')
    dz = f"https://tiba.jsyks.com/Post/{d}.htm"
    # 从网页找到答案
    r = requests.get(url=dz).text
    html = etree.HTML(r)
    daan = html.xpath("/html/body/div[2]/div[4]/div[1]/div[1]/h1/u/text()")
    da = ''.join(daan)


判断对错

# 判断然后点击
    if da == '对':
        driver.find_element(By.XPATH,f'//*[@id="LI{a}"]/b[1]').click()
    elif da == '错':
        driver.find_element(By.XPATH, f'//*[@id="LI{a}"]/b[2]').click()
    elif da == 'A':
        driver.find_element(By.XPATH, f'//*[@id="LI{a}"]/b[1]').click()
    elif da == 'B':
        driver.find_element(By.XPATH, f'//*[@id="LI{a}"]/b[2]').click()
    elif da == 'C':
        driver.find_element(By.XPATH, f'//*[@id="LI{a}"]/b[3]').click()
    else:
        driver.find_element(By.XPATH, f'//*[@id="LI{a}"]/b[4]').click()
    a += 1

点击交卷

# 点击交卷
driver.find_element(By.CLASS_NAME,'btnJJ').click()
time.sleep(5)
driver.quit()

看效果

python爬虫selenium自动化-实现科目一自动答题_HTML_05

公众号回复 自动答题 获取源代码

感谢观看


【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  wURKzOHw9Irf   2023年12月24日   29   0   0 HTMLicoicohtml
  8l4CZpTOKa7P   2023年12月26日   40   0   0 htmlhtml
  dwHry2iKGG0I   2023年12月26日   31   0   0 githubgithubhtmlhtml
WIU1Qlm7CwPb