大家好,我是天空之城包竹。今天給大家?guī)硇「@?/p>
import requests, openpyxl
header = {
'Referer': 'https://www.zhihu.com/people/zhang-jia-wei/posts?page=3',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; rv:46.0) Gecko/20100101 Firefox/46.0'}
# 創(chuàng)建工作簿
wb = openpyxl.Workbook()
# 獲取工作簿的活動表
sheet = wb.active
# 工作表重命名
sheet.title = 'lyrics'
sheet['A1'] = '標題' # 加表頭燕酷,給A1單元格賦值
sheet['B1'] = '摘要' # 加表頭,給B1單元格賦值
sheet['C1'] = '鏈接' # 加表頭周瞎,給C1單元格賦值
for i in range(0,200,20):
url = 'https://www.zhihu.com/api/v4/members/zhang-jia-wei/articles?include=data%5B*%5D.comment_count%2Csuggest_edit%2Cis_normal%2Cthumbnail_extra_info%2Cthumbnail%2Ccan_comment%2Ccomment_permission%2Cadmin_closed_comment%2Ccontent%2Cvoteup_count%2Ccreated%2Cupdated%2Cupvoted_followees%2Cvoting%2Creview_info%2Cis_labeled%2Clabel_info%3Bdata%5B*%5D.author.badge%5B%3F(type%3Dbest_answerer)%5D.topics&offset={}&limit=20&sort_by=created'.format(str(i))
res = requests.get(url,headers=header)
json_blog = res.json()
list_blog = json_blog['data']
for blog in list_blog:
name = blog['title']
content = blog['excerpt']
link = blog['url']
sheet.append([name, content, link])
print('文章名:' + name + '\n' + '摘要:' + content + '\n' + '文章鏈接:' + link)
# 最后保存并命名這個Excel文件
wb.save('zhangjiawei3.xlsx')