Python检测域名是否被微信封禁

Python检测域名是否被微信封禁

浮梦 108 2023-10-11

直接上代码,有能力的直接看着转换其他代码,其实很简单,主要就是头部,头部必须是咱们微信的一个User-Agent请求头。
另外https://mp.weixinbridge.com/mp/wapredirect?url=这个是微信官方的一个接口。

import requests

headers = {
    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
    "Accept-Encoding": "gzip, deflate, br",
    "Accept-Language": "zh-CN,zh;q=0.9,zh-TW;q=0.8,en-US;q=0.7,en;q=0.6",
    "Upgrade-Insecure-Requests": "1",
    "User-Agent": "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.117 Mobile Safari/537.36 MicroMessenger/7.0.16.1320(0x27000C35) NetType/WIFI Language/zh_CN"
}
domain = "https://blog.fudream.cn/"
checkurl = "https://mp.weixinbridge.com/mp/wapredirect?url="+domain
# allow_redirects防止302直接跳转,方便我们拿到302状态码
r = requests.get(checkurl, headers=headers, allow_redirects=False)
if r.status_code == 301 or r.status_code == 302:
	rsp = r.headers["Location"]
	if "weixin110.qq.com" in rsp:
		print(domain+"遭到封禁")
   else:
		print(domain+"未遭到封禁")