如图,比如说我要爬大头死变态的关注人数 已知 URL 为:https://www.zhihu.com/people/wang-ni-ma-94/followers?page=1 通过抓包发现网站信息是动态加载的,然后顺藤摸瓜找到了对应的疑似 json 文件 api 接口为: https://www.zhihu.com/api/v4/members/wang-ni-ma-94/followers?include=data%5B*%5D.answer_count%2Carticles_count%2Cgender%2Cfollower_count%2Cis_followed%2Cis_following%2Cbadge%5B%3F(type%3Dbest_answerer)%5D.topics&offset=20&limit=20
在浏览器打开后是形如下的一段文本,疑似 json:
// 20180122152224 // https://www.zhihu.com/api/v4/members/wang-ni-ma-94/followers?include=data%5B*%5D.answer_count%2Carticles_count%2Cgender%2Cfollower_count%2Cis_followed%2Cis_following%2Cbadge%5B%3F(type%3Dbest_answerer)%5D.topics&offset=20&limit=20 { "paging": { "is_end": false, "totals": 614311, "previous": "http://www.zhihu.com/api/v4/members/wang-ni-ma-94/followers?include=data%5B%2A%5D.answer_count%2Carticles_count%2Cgender%2Cfollower_count%2Cis_followed%2Cis_following%2Cbadge%5B%3F%28type%3Dbest_answerer%29%5D.topics&limit=20&offset=0", "is_start": false, "next": "http://www.zhihu.com/api/v4/members/wang-ni-ma-94/followers?include=data%5B%2A%5D.answer_count%2Carticles_count%2Cgender%2Cfollower_count%2Cis_followed%2Cis_following%2Cbadge%5B%3F%28type%3Dbest_answerer%29%5D.topics&limit=20&offset=40" }, "data": [ { "is_followed": false, "avatar_url_template": "https://pic2.zhimg.com/9256b7b963c816a5b5cae6b4b9b67bcf_{size}.jpg", "user_type": "people", "answer_count": 0, "is_following": false, "url": "http://www.zhihu.com/api/v4/people/44ced3e1aa77f2aac54447cc5219e523", "type": "people", "url_token": "zack-71-48", "id": "44ced3e1aa77f2aac54447cc5219e523", "articles_count": 0, "name": "zack", "headline": "", "gender": -1, "is_advertiser": false, "avatar_url": "https://pic2.zhimg.com/9256b7b963c816a5b5cae6b4b9b67bcf_is.jpg", "is_org": false, "follower_count": 0, "badge": [ ...... 之所以说疑似,是因为我在使用 requests.get(url).json()之后报错: json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
网上搜一了一下,说有可能不是合法的 json 文件 有哪位大兄 dei 知道怎么破吗? ps:因为这网站不能发图片,所以排版会丑一点,大家别见怪哈!
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.