Fiddler安裝和設置
安裝
Fiddler 安裝包可以從這里獲取,如果失效了可以自己網上找一個安裝。
鏈接:https://pan.baidu.com/s/1N30BoDWm2_dBL8i8GRzK5g?pwd=1znv?
提取碼:1znv?
然后就是點擊安裝就好了,沒什么好多說的。
啟用HTTPS捕獲
進入軟件界面,點擊 Tools -> Options -> HTTPS 啟用捕獲 https 請求并解密。
證書信任
設置信任根證書,不然進行抓包捕獲時,其他網頁就訪問不了了。
?
設置自動轉發
設置指定 url 自動轉發到本地,我這里是自動把請求轉發到了我本地一個 Flask 搭建的服務,設置好以后進行保存(轉發地址記得和你服務的地址保持一致)。
設置自動轉發 https://search.weixin.qq.com/cgi-bin/wxaweb/wxindexfluctuations?的目的主要是為了獲取數據請求參數中的 openid 和 search_key,因為我需要這兩個請求參數去構造新的 body。
開啟捕獲
可以從 File -> Capture Traffic 開啟捕獲,也可以用 F12 快捷鍵開啟捕獲,當左下角有 Capturing 字樣時,表示捕獲已開啟。
數據抓取處理
搭建并啟動本地服務
可以自己在本地簡單寫一個服務接收和轉發的請求并處理。我這里構造了兩個 body 去分別獲取 指數趨勢 和 數據來源。
# coding:utf-8
import datetime
import json
import pygal
from pygal.style import Styleimport requests
import urllib3
from flask import Flask, requestapp = Flask(__name__)headers = {'Host': 'search.weixin.qq.com','Connection': 'keep-alive',# 'Content-Length': '182','xweb_xhr': '1','User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) NetType/WIFI MiniProgramEnv/Windows WindowsWechat/WMPF WindowsWechat(0x6309092b) XWEB/9129','Content-Type': 'application/json','Accept': '*/*','Sec-Fetch-Site': 'cross-site','Sec-Fetch-Mode': 'cors','Sec-Fetch-Dest': 'empty','Referer': 'https://servicewechat.com/wxc026e7662ec26a3a/53/page-frame.html','Accept-Encoding': 'gzip, deflate, br','Accept-Language': 'zh-CN,zh;q=0.9',}def draw_line(title, time_indexes, last_day=7):time_indexes = time_indexes[-last_day:]date_chart = pygal.StackedLine(fill=True, interpolate='hermite', x_label_rotation=-20, style=pygal.style.LightGreenStyle)date_chart.x_labels = [str(x["time"])[4:] for x in time_indexes]date_chart.add(title, [x["score"] for x in time_indexes])date_chart.render_to_file(f"line.svg")def draw_pie(title, channel_scores, last_day=7):# 顏色對應關系可以使用 pyautogui 的 getpixel 取色器獲取# colors_map = {# "ad_score": "#eda150",# "extlink_score": "#a9e87a",# "finder_score": "#f6c443",# "live_score": "#ff6146",# "mpdoc_score": "#7c160",# "query_score": "#4fadf8"# }# style = Style(colors=("#eda150", "#a9e87a", "#f6c443", "#ff6146", "#7c160", "#4fadf8"))legend_map = {"ad_score": "其他","extlink_score": "網頁","finder_score": "視頻號","live_score": "直播","mpdoc_score": "公眾號","query_score": "搜一搜",}channel_scores = channel_scores[-last_day:]channel_scores = [c["channel_score"] for c in channel_scores]channel_score = channel_scores.pop()for cs in channel_scores:for key, score in cs.items():channel_score[key] += score# pie_chart = pygal.Pie(inner_radius=0.5, style=pygal.style.LightSolarizedStyle)pie_chart = pygal.Pie(inner_radius=0.5)pie_chart.title = title# print(channel_score)total_score = channel_score["total_score"]for key, score in channel_score.items():if key in ["score_exp", "total_score"]:continuepercent = float("{:.2f}".format(100 * score / total_score))pie_chart.add(legend_map[key], percent)pie_chart.render_to_file(f"pie.svg")@app.route('/post_data', methods=['POST'])
def post():if request.method == 'POST':urllib3.disable_warnings()data = request.get_json()# print(data)openid = data.get("openid")search_key = data.get("search_key")query = [data.get("query")]end_ymd = datetime.datetime.now().strftime("%Y%m%d")start_ymd = (datetime.datetime.now() - datetime.timedelta(365)).strftime("%Y%m%d")forward_url = 'https://search.weixin.qq.com/cgi-bin/wxaweb/wxindex'# 指數趨勢json_data = {'openid': openid, 'search_key': search_key, 'cgi_name': 'GetDefaultIndex','query': query, 'compound_word': [], 'start_ymd': start_ymd, 'end_ymd': end_ymd}response = requests.post(forward_url, json=json_data, headers=headers, verify=False)response_data = response.json()# json.dump(response_data, open("test1.json", "w"), indent=2)# print(response_data)# returntitle = response_data["content"]["resp_list"][0]["query"]time_indexes = response_data["content"]["resp_list"][0]["indexes"][0]["time_indexes"]# print(time_indexes)draw_line(title, time_indexes, 30)# # 數據來源json_data2 = {'openid': openid, 'search_key': search_key, 'cgi_name': 'GetMultiChannel','query': query, 'start_ymd': start_ymd, 'end_ymd': end_ymd}response = requests.post(forward_url, json=json_data2, headers=headers, verify=False)response_data = response.json()# json.dump(response_data, open("test2.json", "w"), indent=2)result_list = response_data["content"]["result_list"]draw_pie(title, result_list, 30)return {}if __name__ == '__main__':app.run(host="127.0.0.1", debug=True)
小程序搜索關鍵字
- 進入電腦端微信
- 搜索 微信指數 小程序
- 進入小程序,輸入想要搜索的關鍵詞(比如:和平精英)
數據圖表展示
微信圖表展示如下:
我們自己使用 pygal 畫的圖如下(svg 圖用瀏覽器打開),對比發現,除了插值導致的光滑度不一樣,圖的整體走勢是一致的: