from selenium import webdriver
from selenium.webdriver.chrome.options import Options
option=Options()
# executable设置msedgedriver所在位置
driver=webdriver.Edge(executable_path='D:\\Software\\edgedriver_win32\\msedgedriver.exe')
driver.maximize_window()
#设置窗口的大小
from time import sleep
driver.get('https://mooc1.chaoxing.com/mooc2/work/view?courseId=226025825&classId=58055417&cpi=169277503&workId=20899904&answerId=51266676&enc=79592be5222b5b431b4653ba2d30fdc1&selectTimes=1')
account=input('请输入账号:')
password=input('请输入密码:')
driver.find_element_by_class_name("ipt-tel").send_keys(account)
driver.find_element_by_class_name("ipt-pwd").send_keys(password)
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.select import Select
driver.find_element_by_id("loginBtn").click()
n=eval(input("请输入要爬取的网址个数:"))
url=[]
pd=input("请输入y确定n取消:")
if pd=='y':
for i in range(n):
url.append(input("请输入网址:"))
m=0
for q in url:
driver.get(q)
findbook=driver.find_elements_by_tag_name('h3')
findbook1=driver.find_elements_by_xpath('//span[@class="colorGreen marginRight40 fl"]')
findbook2=driver.find_elements_by_xpath('//ul[@class="mark_letter colorDeep"]')
a=[]
b=[]
c=[]
d=[]
e=[]
for i in findbook:
a.append(i.text)
# d=a[8:]
for ii in findbook1:
b.append(ii.text)
for iii in findbook2:
e.append(iii.text)
for i in range(len(b)):
c.append(a[i]+'\n'+e[i]+'\n'+b[i]+'\n')
print(c)
with open("题库"+str(m)+".txt","wt",encoding='utf-8') as f:
for i in c:
f.write(str(i))
m+=1
else:
print("退出")
cxmg题库爬虫
于 2023-11-05 14:43:02 首次发布