import requests
from lxml import etree
import csv
import pandas
class CSDNspider:
#爬取csdn学院所有课程名、价格
def __init__(self):
self.url='https://edu.csdn.net/courses/o280_s355'
def fenqu(self):
response=requests.get(self.url).content
neirong=etree.HTML(response)
each1=neirong.xpath('//div[@class="course_item acsdnd_item"]')
each2 = neirong.xpath('//div[@class="course_item"]')
return each1,each2
def name(self,each1,each2): # 得到课程名列表
text=[]
for e in each1:
name=e.xpath('.//dt/div[@class="titleInfor ellipsis-2"]/text()')[0] #if len(e.xpath('./dt/div[@class="titleInfor ellipsis-2"]/text()'))>0 else None
#print(type(name))
text.append(name)
for e in each2:
name1=e.xpath('.//span[@class="title ellipsis-2"]/@title'