1. 程式人生 > >json數據爬蟲。requests實現

json數據爬蟲。requests實現

item clas mom mozilla als += erl 姓名 esp

import json
import requests

# url = "https://www.mamalaile.cn/mamalailegw/page/waiterList.jsp"
url = "https://www.mamalaile.cn/momcome-app/waiter/api_queryUserWaiterInfo.do"

headers = {
    ‘User-Agent‘: ‘Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36‘
}

response = requests.get(url, headers=headers)
data_str = response.content.decode()
data_dict = json.loads(data_str)
print(type(data_dict))
print(len(data_dict[‘data‘]))
print(data_dict[‘data‘][0][‘name‘])
i = 0
for item in data_dict[‘data‘]:
    i += 1
    print(str(i))
    print(‘姓名:%s‘%item[‘name‘])
    print(‘年齡:%s‘%item[‘age‘])
    print(‘籍貫:%s‘%item[‘place‘])
    print(‘屬相:%s‘%item[‘animals‘])

  

json數據爬蟲。requests實現