看到别人分享的就业班各个课程url规律很简单,所以python写下查找各个就业班,视频在精不在多,希望找到合适自己的视频
url规律: https://www.imooc.com/course/programdetail/pid/n(n代表任意数字),
n不要太大了,太大估计没有,这个是按照数据库id自增策略来的吧
# -*- coding: utf-8 -*-
"""
环境:python+ selenium
找就业班课程工具
找慕课网实战就业班教程,看了下很多都是免费的,初级中级居多,质量应该还不错
"""
from selenium import webdriver
if __name__=='__main__':
driver = webdriver.Chrome()
index = 1
inp = ''
courses = []
print('输入q 终止循环,输入a添加记录并循环,输入其它任意继续循环')
while(inp!=None and inp != 'q'):
course_url = 'https://www.imooc.com/course/programdetail/pid/%d'%index
driver.get(course_url)
index = index +1
elements = driver.find_elements_by_class_name('errorwarp')
if len(elements)>0:
print('\t页面错误: url=%s'%course_url)
continue
inp = input("输入操作:")
if inp !=None and inp=='a':
courses.append(course_url)
pass
print(courses)
# 1跑到20: ['https://www.imooc.com/course/programdetail/pid/11', 'https://www.imooc.com/course/programdetail/pid/17', 'https://www.imooc.com/course/programdetail/pid/18', 'https://www.imooc.com/course/programdetaa/pid/20']]