简单的爬虫0x01:实现爬i春秋"知识体系"课程名称

以下为全部代码实现,python版本为3.6.4

#! coding=utf-8

import requests
import json
import urllib

def lesson(i):
    url= 'https://www.ichunqiu.com/courses/ajaxCourses'
    header={
            'Host': 'www.ichunqiu.com',
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:58.0) Gecko/20100101 Firefox/58.0',
            'Accept': 'application/json, text/javascript, */*; q=0.01',
            'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
            'Accept-Encoding': 'gzip, deflate',
            'Referer': 'https://www.ichunqiu.com/courses',
            'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
            'X-Requested-With': 'XMLHttpRequest',
            'Content-Length': '102',
            'Connection': 'close',
    }
    data_post={'courseTag':'','courseDiffcuty':'','IsExp':'','producerId':'','orderField':'','orderDirection':'','pageIndex':i,'tagType':'','isOpen':''}
    r=requests.post(url=url,headers=header,data=data_post)
    data=json.loads(r.text)
    #print(r.text)
    #code = r.status_code
    #print(code)
    for name in data['course']['result']:
        print (name['courseName'])

for i in range(1,19):
    lesson(i)
  • Copyrights © 2018-2021 rich4rd
  • Visitors: | Views: