本文整理汇总了Python中course.Course.type方法的典型用法代码示例。如果您正苦于以下问题:Python Course.type方法的具体用法?Python Course.type怎么用?Python Course.type使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类course.Course
的用法示例。
在下文中一共展示了Course.type方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse_course_table
# 需要导入模块: from course import Course [as 别名]
# 或者: from course.Course import type [as 别名]
def parse_course_table (p, tree, table):
courses = []
course_type_path = tree.getpath (table) + "/descendant::a[contains(@class, 'title')]/text()"
course_type = tree.xpath(course_type_path)[0]
codes_path = tree.getpath (table) + "/descendant::td[contains(@class, 'code')]/a"
codes = tree.xpath (codes_path)
codes_title_path = tree.getpath (table) + "/descendant::td[contains(@class, 'title')]/a/text()"
codes_title = tree.xpath (codes_title_path)
if len(codes) != len(codes_title):
print ("Error: lengths don't match with codes and codes_title")
return []
for i in range (len (codes)):
c = Course(codes[i].text)
c.type = parse_course_type (course_type)
c.name = codes_title[i]
c.link = codes[i].get ("href")
for e in codes_title[i].getparent().itersiblings():
if e.tag == "span" and e.get ("class") == "comment":
for p in e.iterchildren():
if p.tag == "p":
c.comment = p.text
courses.append (c)
return courses