程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python crawler forwards article news in real time; Wechat robot use; Suggested collection

編輯:Python

Hello everyone , I meet you again , I'm your friend, Quan Jun .

Preface : current time 2022-4-24 There has been no water article for five months !personally Technology does not increase but regresses , Salty bullshit !

Have a fun today , use “ Ghost hand ” A free version of wechat pc End robot + Crawlers are used to forward articles or news in real time !

thank “ Ghost hand ” Free to share source code !( I just like exclamation marks ! Nothing else ! Not to emphasize !)

One 、 Introduce “ Ghost hand ” Of pc End wechat use

First dump github link :https://github.com/cixingguangming55555/wechat-bot

There are tutorials in it , But for convenience and in line with the principle of speaking in detail, let's talk about it .

1、 Download the source code ( crap 0.0)

2、 Download the corresponding wechat version , The following interfaces are available , because “ Ghost hand ” The following versions are already available dll

All versions of wechat Extraction code :ha4a

3、 Login WeChat , stay server Open wechat under the path DLL injector , Select the corresponding version , Click inject !

4、 Start typing code ,” Ghost hand ” Already in client Some languages are given under the path (java,python…) Templates !

The use of websocket Connect ,websocket It is also divided into long and short connections , We use short connections for convenience !

The following code implements three functions : Query groups and users id、@ Group members send messages 、 Send pictures or files . The code is together , It is split for convenience !

1、 Query groups and users id

# -*- coding:utf-8 -*-
# author:BC
import websocket
import time
import json
SERVER = 'ws://127.0.0.1:5555'
AT_MSG = 550
USER_LIST = 5000
PIC_MSG = 500
ATTATCH_FILE = 5003
def getid():
id = time.strftime("%Y%m%d%H%M%S", time.localtime(time.time()))
return id
# Get the user name and... Of wechat address book wxid
def send_wxuser_list():
qs = {
'id': getid(),
'type': USER_LIST,
'content': 'user list',
'wxid': 'null',
}
s = json.dumps(qs)
return s
# Print group name
def print_wxuser():
ws = websocket.create_connection(SERVER)
ws.send(send_wxuser_list())
result = json.loads(ws.recv())
content = result['content']
for item in content:
id = item['wxid']
m = id.find('@')
if m != -1:
print(f' Wechat group :---->roomid:{id}----name:{item["name"]}')
else:
print(f' user :---->roomid:{id}----name:{item["name"]}')
if __name__ == '__main__':
ws = websocket.create_connection(SERVER)
print_wxuser()

2、@ Group members send messages

# Aite group members The following are required parameters
def send_at_msg(roomid, content, nickname):
j = {
'id': getid(),
'type': AT_MSG,
'roomid': roomid,
'wxid': 'your wxid',
'content': content,
'nickname': nickname,
'ext': 'null'
}
s = json.dumps(j)
return s
if __name__ == '__main__':
roomid = input('Roomid:') # Group id Or user id
content = input('send Content:') # What to send
nickname = input('@ name required:') # By @ The person's name
ws.send(send_at_msg(roomid, content, nickname))
print('[**] Aite succeeded !!!')

3、 Send pictures or files

# Send pictures or files
def send_pic_msg(type, wxid, path):
j = {
'id': getid(),
'type': type,
'wxid': wxid,
'roomid': 'null',
'content': path,
'nickname': "null",
'ext': 'null'
}
s = json.dumps(j)
return s
if __name__ == '__main__':
type = input('[***] Function options ----A、 Send pictures \tB、 Send a file ( Enter upper and lower case letters ):')
wxid = input('wxid:') # Group id Or user id
path = input('path:') # File path to be sent
if type == 'A' or type == 'a':
ws.send(send_pic_msg(PIC_MSG, wxid, path))
print('[**] Picture sent successfully !!!')
elif type == 'B' or type == 'b':
ws.send(send_pic_msg(ATTATCH_FILE, wxid, path))
print('[**] File sent successfully !!!')

Two 、 Get a reptile

Aha, AHA …( I'm going to make a template for the knowledge planet crawler ! I think it's unnecessary to omit !)

3、 ... and 、 Two in one , That's right ! Write a loop to the crawler to keep checking for the latest data , Just realize simple monitoring ! Share new news as soon as possible !

ws = websocket.create_connection(SERVER)
ws.send(send_at_msg(roomid, str(content), nickname)) # Group id、 Content 、@ The person's name
ws.close()

design sketch :

Four 、 Tips

Write a loop , You can send wechat messages all the time !( She or he ignores you , Then bomb him ) Hey, hey, evil ! Don't try easily , Consequence conceit !

Conclusion :

For a long time , I feel like I haven't written ! A lot of rubbish , It's true that water spans ! be it so !

The lonely Wutong spring courtyard locks the clear autumn , Shear constantly , Richard also disorderly …

Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/150698.html Link to the original text :https://javaforall.cn


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved