此次更新的是题库不再重复爬取相同的题目
from selenium import webdriver
from lxml import etree
import requests
import time
import random
import json
from selenium.webdriver.remote.webelement import WebElement
headers = {
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
"Chrome/90.0.4430.93 Safari/537.36 Edg/90.0.818.56 "
}
browser = webdriver.Edge(executable_path = r"C:\Users\baibe\PycharmProjects\reptile\new_reptile\MicrosoftWebDriver.exe")
# 让浏览器发起一个指定url的请求
browser.get("https://www.yooc.me/login")
# 定位标签
account_input = browser.find_element_by_xpath('/html/body/div[2]/div/div/div[2]/div/div[1]/form/div[2]/input')
account_input.send_keys('账号')
password_input = browser.find_element_by_xpath('/html/body/div[2]/div/div/div[2]/div/div[1]/form/div[3]/input')
password_input.send_keys('密码')
# 用page_source获取当前页面的源码数据
response = browser.page_source
tree = etree.HTML(response)
code_url = tree.xpath('/html/body/div[2]/

本文介绍如何利用Python的Selenium库爬取某班级课群的题库,并通过XPath解析题目,关键在于实现了避免重复抓取相同题目的策略。
最低0.47元/天 解锁文章
3014





