本文整理匯總了Python中course.Course.link方法的典型用法代碼示例。如果您正苦於以下問題:Python Course.link方法的具體用法?Python Course.link怎麽用?Python Course.link使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類course.Course
的用法示例。
在下文中一共展示了Course.link方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: parse_course_table
# 需要導入模塊: from course import Course [as 別名]
# 或者: from course.Course import link [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