One: We go through Charles to grab a piece of app request, return the JSON data from the server, and beautify the JSON code through the Chrome plugin Jsonview as shown
We want to grab ID and name
2: Write our code in the PYCHARM environment
# -*- coding: utf-8 -*- __author__ = ' Itiwin ' import requests import json import os import sys import time import traceback import MySQLdb-Reload (SYS) SY S.setdefaultencoding ("Utf-8") conn= mysqldb.connect (host= ' localhost ', port = 3306, user= ') Root ', passwd= ' root ', db = ' Db_expert ', conn.set_character_set (' UTF8 ') cur = conn.cursor () Cur.execu
Te (' set names utf8; ')
Cur.execute (' set character set utf8; ')
Cur.execute (' set character_set_connection=utf8; ') Cur.close () headers = {' Accept ': ' text/html,application/xhtml+xml,application/xml;q=0.9,*/ *;q=0.8 ', ' accept-encoding ': ' gzip, deflate, compress ', ' accept-language ': ' =0.3 ', ' Cache-control ': ' max-age=0 ', ' Connection ': ' keep-alive ', ' user-agent ': ' ( WINDOWS NT 6.1; WOW64) AppleWebKit/537.36 (Khtml, like gecko) chrome/43.0.2357.65 safari/537.36 '}
Session=requests.session ();
Session.headers.update (Headers) Def getnav (): url = ' http://get json url ' r = requeturl (URL) j = r.text jn = json.loads (j) data = jn[' data '] try: print (U ' A total of several categories: ' +str (len (data)) for d in data: id = d[' id '] print ( d[' name ') Getmatchinfo (ID) except: &nbsP; traceback.print_exc (file=sys.stdout) finally: conn.close () session.close () if __ name__ == ' __main__ ': getnav ()