第四次作业

#爬上关注群的投稿信息

import requests

import json

import re

headers = {

    'user-agent':'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.98 Mobile Safari/537.36',

    'cookie':'__yadk_uid=YFb5u9Thri0gsV3Z7JBIY2GG0bh2W1rZ; read_mode=day; default_font=font2; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%2217935277%22%2C%22%24device_id%22%3A%2216a908ea770dd2-0a9c509aba0727-2b6f686a-1049088-16a908ea771b05%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E8%87%AA%E7%84%B6%E6%90%9C%E7%B4%A2%E6%B5%81%E9%87%8F%22%2C%22%24latest_referrer%22%3A%22https%3A%2F%2Fwww.baidu.com%2Flink%22%2C%22%24latest_referrer_host%22%3A%22www.baidu.com%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC%22%2C%22%24latest_utm_source%22%3A%22desktop%22%2C%22%24latest_utm_medium%22%3A%22timeline%22%7D%2C%22first_id%22%3A%2216a908ea770dd2-0a9c509aba0727-2b6f686a-1049088-16a908ea771b05%22%7D; Hm_lvt_0c0e9d9b1e7d617b3e6842e85b9fb068=1560309203,1560309223,1560309233,1560317358; Hm_lpvt_0c0e9d9b1e7d617b3e6842e85b9fb068=1560317842; locale=zh-CN; _m7e_session_core=90778f12f43d92bd8964c75d1269238e'

}

url = 'https://www.jianshu.com/subscriptions/18782404'

def get_info(url):

    res = requests.get(url,headers=headers)

    json_data = json.loads(res.text)

    sources = json_data['source']['notes']

    for source  in  sources:

        # id = source['id']

        title = source['title']

        nickname = source['author']['nickname']

        public_abbr = source['public_abbr']

        # print(source)

        print(nickname,title,public_abbr)

get_info(url)

你可能感兴趣的:(第四次作业)