【小白必备】小程序内容页面接入 python数据提交工具
发布于 3 年前 作者 mingxiao 4871 次浏览 来自 分享


python环境教学按照视频里面大概半个小时完成
教学地址:https://www.bilibili.com/video/BV12E411A7ZQ
然后复制代码  把appid, secret填进去
页面路径批量生成后就可以运行了。

觉得不错就点个赞!!

import requests
import json
import os
from fake_useragent import UserAgent

location = os.getcwd() + '/fake_useragent.json'
ua = UserAgent(path=location)
header = {"User-Agent": ua.random}

# 获取小程序的access-token值
url = "https://api.weixin.qq.com/cgi-bin/token"

# 配置自己小程序的个人信息
param = {"grant_type": "client_credential", "appid": "这里填appid", "secret": "这里填secret"}

# 提交小程序页面信息真实页面路径
access_param = {"pages": [
    {
        "path": "tyyfs/pages/info/index",
        "query": "id=34"
    },
    {
        "path": "tyyfs/pages/info/index",
        "query": "id=35"
    },
    {
        "path": "tyyfs/pages/info/index",
        "query": "id=36"
    },
    {
        "path": "tyyfs/pages/info/index",
        "query": "id=37"
    },
]
}

try:
    # 发起请求获取access-token值
    res = requests.get(url, headers=header, params=param)
    if res.status_code == 200:
        content = json.loads(res.text)
        print(content)
        access_token = content['access_token']
        print("access:", access_token)

        # 构造收录页面的地址
        access_url = "https://api.weixin.qq.com/wxa/search/wxaapi_submitpages?access_token={}".format(access_token)
        try:
            # 发起第二次请求,请求微信官方进行收录自己小程序的页面
            res = requests.post(access_url, headers=header, data=json.dumps(access_param))
            if res.status_code == 200:
                print(res.text)
            else:
                print("状态码:", res.status_code)
                print(res.text)
        except Exception as e:
            print("fail:", e)

    else:
        print("状态码:", res.status_code)
        print(res.text)
except Exception as e:
    print("fail:", e)

回到顶部