爬虫练习1:爬知乎关注人信息

记录练习爬虫的过程
爬取知乎关注人信息
学习了requests和pandas

import requests
import pandas as pd

shuju=[]
header={
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36',
    'authority': 'www.zhihu.com'
}
def paichong(page):
    for i in range(page):
        url='https://www.zhihu.com/api/v4/members/Miss.Jiang/followees?include=data%5B*%5D.answer_count%2Carticles_count%2Cgender%2Cfollower_count%2Cis_followed%2Cis_following%2Cbadge%5B%3F(type%3Dbest_answerer)%5D.topics&offset={}&limit=20'.format(i*20)
        response=requests.get(url,headers=header)
        response.encoding='utf-8'
        response=response.json()['data']
        shuju.extend(response)
        print('正在爬取第%s页'%str(i+1))
if __name__ == '__main__':
    paichong(16)
    df=pd.DataFrame.from_dict(shuju)
    df.to_excel('shuju1.xls')
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值