下面的代码基于千寻框架,都测试过了,都能正常使用。
需要项目代码或者千寻框架的可以加我V:iostreamX64
注意:批量加好友的时候记得设置个时间间隔,加好友太频繁微信会被封的。
导出微信群员信息
import pandas as pd
from lib.data import *
from config import wxbot_id, qun_id
# 导出信息
output_filename = "output.xlsx"
group_info = group_member_list(qun_id=qun_id)
results = [object_information(wxid) for wxid in group_info]
# 创建一个空的DataFrame来存储结果
df = pd.DataFrame(columns=["wxid", "昵称", "微信号"])
for item in results:
wxid = item['wxid']
wxNum = item['wxNum']
nick = item['nick']
# 检查wxid是否为空,如果为空则跳过此条记录
if wxid:
# 向数据框添加一行新的数据
df = df.append({"wxid": wxid, "昵称": nick, "微信号": wxNum}, ignore_index=True)
# 将数据框保存为Excel文件
df.to_excel(output_filename, index=False)
批量添加好友
from lib.data import add_friend
def read_wxids_from_file(filename):
wxids = []
with open(filename, "r", encoding="utf-8") as file:
for line in file:
wxid = line.strip().split("wxid: ")[-1].split(",")[0]
if wxid:
wxids.append(wxid)
return wxids
if __name__ == "__main__":
wxids = read_wxids_from_file("output.txt")
message = "你好"
for wxid in wxids:
result = add_friend(wxid, message)
print(result)
导出微信好友
import requests
import json
url = "http://127.0.0.1:7777/DaenWxHook/httpapi/?wxid=wxid_k3p7e171sph522"
payload = json.dumps({
"type": "Q0005",
"data": {
"type": "1"
}
})
headers = {
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
'Content-Type': 'application/json'
}
response = requests.request("POST", url, headers=headers, data=payload)
# 使用 response.json() 直接解析JSON响应
parsed_data = response.json()
# 提取wxid、wxNum和nick字段
result = parsed_data["result"]
# 创建一个用于存储提取数据的字符串
extracted_data_str = ""
for entry in result:
wxid = entry["wxid"]
wxNum = entry["wxNum"]
nick = entry["nick"]
extracted_data_str += f"wxid: {wxid}\nwxNum: {wxNum}\nnick: {nick}\n---\n"
# 将提取的数据保存到.txt文件中
output_filename = "extracted_data.txt"
with open(output_filename, "w") as outfile:
outfile.write(extracted_data_str)
print(f"提取的数据已保存到文件 {output_filename}")