---
# System prepended metadata

title: Untitled

---

分析到此我们便可构造参数来编写自定义微信小程序搜索的脚本，其Python程序源码如下：

```python
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
import requests,json,sys

def Get_Apps(query,number,cookie):
    headers={"User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/7.0.11(0x17000b21) NetType/WIFI Language/fr"}
    url = "https://mp.weixin.qq.com/wxa-cgi/innersearch/subsearch"
    params = "query=" + query + "&cookie=" + cookie + '&subsys_type=1&offset_buf={"page_param":[{"subsys_type":1,"server_offset":0,"server_limit":' + str(int(number)+30) + ',"index_step":' + number + ',"index_offset":0}],"client_offset":0,"client_limit":' + number + '}'
    response = requests.post(url=url, params=params, headers=headers).text
    Apps_Json = json.loads(response)
    App_Items = Apps_Json['respBody']['items']
    for App_Item in App_Items:
        App_Item_Json = json.loads(json.dumps(App_Item)) #重新加载嵌套内容中的json数据
        App_Id = App_Item_Json['appid']
        App_Name = App_Item_Json['nickName']
        App_Id_List.append(App_Id)
        App_Name_List.append(App_Name)

if __name__ == '__main__':
    reload(sys)
    sys.setdefaultencoding('utf-8') #解决编码问题
    query = raw_input("请输入要搜的微信小程序名称: ")
    number = raw_input("请指定要返回的小程序的数量: ")
    cookie = raw_input("请输入你获取到的Cookie信息: ")
    App_Id_List = []
    App_Name_List = []
    try:
        Get_Apps(query,number,cookie)
        print "返回的小程序名: " + ",".join(App_Name_List)
        print "返回的小程序ID: " + ",".join(App_Id_List)
    except:
        print "信息获取失败，请检查！"
```

那么接下来我们便要开始写微信小程序网络接口的批量提取脚本，但这边有一个小细节需要注意，此接口的访问频率有一定的限制，每访问一次需要将程序“休眠”数秒再进行下一次访问，若触发其访问频率限制则会提示“访问频繁，请稍后再试”，并会对你当前身份封锁15分钟左右。最后完成的Python源码如下：

```Python
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
import requests,time

def Get_Domain(X_APP_ID,X_WECHAT_KEY,X_WECHAT_UIN):
    headers={
    "User-Agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/7.0.11(0x17000b21) NetType/WIFI Language/fr",
    "X-WECHAT-KEY": X_WECHAT_KEY,
    "X-WECHAT-UIN": X_WECHAT_UIN #微信两个校验值
    }
    url = "https://mp.weixin.qq.com/mp/waverifyinfo"
    params = "action=get&wx_header=1&appid=" + X_APP_ID
    response = requests.get(url=url, params=params, headers=headers).text
    Response_domain_list =  Get_MiddleStr(response,"request_domain_list","request_domain_list.splice")
    Response_domain_list = Get_MiddleStr(Response_domain_list,"= ",";")
    exec("Domain_list.extend(" + Response_domain_list + ")") #添加list数组
    time.sleep(8) #防止访问频繁，自己调节

def Get_MiddleStr(content,startStr,endStr): #获取中间字符串的一个通用函数
    startIndex = content.index(startStr)
    if startIndex>=0:
        startIndex += len(startStr)
    endIndex = content.index(endStr)
    return content[startIndex:endIndex]

if __name__ == '__main__':
    X_APP_IDS = raw_input("请输入小程序ID(逗号分隔): ")
    X_WECHAT_UIN = raw_input("请输入自己的X-WECHAT-UIN: ")
    X_WECHAT_KEY = raw_input("请输入自己的X-WECHAT-KEY: ")
    X_APPID_LIST = X_APP_IDS.split(",")
    Domain_list = []
    for X_APP_ID in X_APPID_LIST:
        try:
            Get_Domain(X_APP_ID,X_WECHAT_KEY,X_WECHAT_UIN)
        except:
            print X_APP_ID + "的信息获取失败，请检查！"
    Domain_list = list(set(Domain_list)) #list数组去重
    Domain_list = filter(None,Domain_list) #list数组去空
    print "收集到的域名: " + str(Domain_list)
```