第四周作业

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/58.0.3029.110 Mobile Safari/537.36',

    'cookie':'__yadk_uid=qBZWgOdcv9bASkYYG9q3SwgvIZLX4PmR; remember_user_token=W1sxNzkzOTIxN10sIiQyYSQxMSR0TFUwRWF4S3gyRUdERkRyVXZvQ0NPIiwiMTU2MDMwMzM2OC4wODg1Nzg1Il0%3D--2c397545aa7c35ffb26b959c544eae86589fe8cf; read_mode=day; default_font=font2; mobile-index-modal=1; Hm_lvt_0c0e9d9b1e7d617b3e6842e85b9fb068=1559119165,1559636622,1559803145,1560303373; Hm_lpvt_0c0e9d9b1e7d617b3e6842e85b9fb068=1560303418; locale=zh-CN; _m7e_session_core=823dafb802de27026f0c8285d980e964; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%2216ade902ad73fc-0a0e2fa753a26a-4d045769-1049088-16ade902ad8954%22%2C%22%24device_id%22%3A%2216ade902ad73fc-0a0e2fa753a26a-4d045769-1049088-16ade902ad8954%22%2C%22props%22%3A%7B%22%24latest_traffic_source_type%22%3A%22%E7%9B%B4%E6%8E%A5%E6%B5%81%E9%87%8F%22%2C%22%24latest_referrer%22%3A%22%22%2C%22%24latest_referrer_host%22%3A%22%22%2C%22%24latest_search_keyword%22%3A%22%E6%9C%AA%E5%8F%96%E5%88%B0%E5%80%BC_%E7%9B%B4%E6%8E%A5%E6%89%93%E5%BC%80%22%2C%22%24latest_utm_source%22%3A%22desktop%22%2C%22%24latest_utm_medium%22%3A%22search-recent%22%7D%2C%22first_id%22%3A%22%22%7D',

}

url ='https://www.jianshu.com/asimov/trending/now?count=15¬e_ids='

def get_info(url,page):

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

json_data = json.loads(res.text)

print(json_data)

for iin range(0,20):

ids=json_data[i]['object']['data']['id']

objects = json_data[i]['object']['data']['title']

print(ids,objects)

get_info(url,1)

#获取了首页上,用户发表的文章名称和作者的ID

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