-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcourse.py
More file actions
42 lines (37 loc) · 1.17 KB
/
course.py
File metadata and controls
42 lines (37 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#/usr/bin/python
# encoding:utf-8
# __Author__ = Slwhy
from tools_my.crawls import Crawl
from bs4 import BeautifulSoup
class Course(Crawl):
name = ''
def get_courses(self,url):
courses_list = []
html =self.getText(url)
soup = BeautifulSoup(html,'html.parser')
cf = soup.find_all('ul',class_= 'cf')
for ul in cf:
try:
li = ul.find_all('li')
for i in li:
id = i.get('id')
name = i.find('h2').get_text()
# url = 'http://www.jikexueyuan.com/course/%s.html'%id
tup = (id,name)
courses_list.append(tup)
except:
print '获取 course 列表失败'
continue
return courses_list
def get_num_classes(self,url):
html = self.getText(url)
soup = BeautifulSoup(html,'html.parser')
try:
box = soup.find('div',class_="lesson-box")
ul = box.ul
li = ul.find_all('li')
num = li.__len__()
return num
except:
print 'get the list of classes error'
return 0