微信公众号+获取文章内容【只是记录自己的学习过程】
生活随笔
收集整理的這篇文章主要介紹了
微信公众号+获取文章内容【只是记录自己的学习过程】
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
fiddler抓包獲取公眾號文章頁面鏈接
1,類型地址
https://redu.lopao.com/api/article/cate
2,具體文章鏈接
https://redu.lopao.com/api/article/lists?category=mil&page=0
問題描述
需要注意的是,這里不能請求到某個類別的所有頁面,只需稍做處理即可
源碼如下:
class wechatSpider:def __init__(self):"""數據初始化"""self.url = 'https://redu.lopao.com/api/article/cate'self.headers = {'User-Agent':UserAgent().random}def get_PageRes(self, url):"""頁面響應:return:"""try:res = requests.get(url=url, headers=self.headers)if res.status_code == 200:return res.textexcept Exception as e:passdef getHtml(self):"""數據解析:return:"""typeData = self.get_PageRes(url=self.url)typeDataList = json.loads(typeData)item = {}for typeData in typeDataList['data']:# 用戶提示print(typeData['text'], end=' ')k = typeData['text']v = typeData['name']item[k] = vprint('\n')word = input('請輸入分類名稱:').strip()if word in item.keys():self.getAllPage(item[word])else:print('---輸入有誤,請重新輸入---')某個類別的所有頁
def getAllPage(self, word):"""獲取所有文章鏈接:param word::return:"""count = 0while True:url = 'https://redu.lopao.com/api/article/lists?category={}&page={}'.format(word, count)infoData = self.get_PageRes(url)dataList = json.loads(infoData)['data']if dataList['next_item'] != None:infoUrl = url.format(word, count+1)data = self.get_PageRes(infoUrl)self.getInfoData(data)else:print('---已獲取所有文章鏈接---')breakcount += 1數據已字典的格式輸出
def getInfoData(self, data):"""數據處理:return:"""item = {}infoData = json.loads(data)['data']for dataInfo in infoData['data']:item['title'] = dataInfo['title']item['src'] = dataInfo['src']item['desc'] = dataInfo['desc']item['url'] = dataInfo['url']print(item)總結
以上是生活随笔為你收集整理的微信公众号+获取文章内容【只是记录自己的学习过程】的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 2021-2027全球与中国汽车CMOS
- 下一篇: 淘宝无线端店铺权重提升方法技巧步骤