Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does Python make Mini Program to send on-screen comments automatically?

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to make Python to send on-screen comment Mini Program automatically". In daily operation, I believe many people have doubts about how to make Python to send on-screen comment Mini Program automatically. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts about "how to make Python send on-screen comment automatically". Next, please follow the editor to study!

Video explanation of climbing bilibili on-screen comment by Python

Https://www.bilibili.com/video/BV1954y1r7pi/

Basic development environment

Python 3.6

Pycharm

Use of related modules

Import requestsimport timefrom tkinter import * import random

one

two

three

four

Target web page analysis

First of all, you need to log in to the bilibili account, and then click on one of the live rooms. Here, it is recommended to choose the ones with less popularity and less on-screen comments, so it is convenient to view the results.

As shown in the figure above, open the developer tool, locate the xhr input and send content, click send, and there will be a send data interface for post requests.

So you only need to request this data interface to send the on-screen comment.

It is normal to crawl data, just like using requests to request web pages, in general, we all use get requests, here we need to use post requests.

So, as long as you give the request an endless loop, you can send on-screen comments all the time, and then customize the content of the on-screen comments so that it can be randomly selected and sent each time.

The complete code import requestsimport timefrom tkinter import * import randomlis_text = ['666','VJ is awesome', 'Love, Love', 'focus on walking, live to 99 years, awesome!!' , 'Xiuer, is that you?'] Def send (): a = 0 while True: time.sleep (2) send_meg = random.choice (lis_text) roomid = entry.get () ti = int (time.time ()) url = 'https://api.live.bilibili.com/msg/send' data = {' color': '16777215,' fontsize': '25' 'mode':' 1', 'msg': send_meg,' rnd':'{} '.format (ti),' roomid':'{} '.format (roomid),' bubble':'0', 'csrf_token':' copy own', 'csrf':' copy own' } headers = {'cookie':' use your own cookie', 'origin':' https://live.bilibili.com', 'referer':' https://live.bilibili.com/blanc/1029?liteVersion=true', 'user-agent':' Mozilla/5.0 (Windows NT 10.0 WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36',} a + = 1 response = requests.post (url=url, data=data, headers=headers) print (response) text.insert (END The text box scrolls text.see (END) # update text.update () text.insert (END, 'send content: {}' .format (send_meg)) root = Tk () root.title ('bilibili automatically sends on-screen comment') root.geometry ('560x450 / 4003200') label = Label (root, text=', please enter room ID:' Font= ('Chinese Xingkai', 20) label.grid () entry = Entry (root, font= ('official script', 20)) entry.grid (row=0, column=1) text= Listbox (root, font= ('official script', 16), width=50, heigh=15) text.grid (row=2, columnspan=2) button1 = Button (root, text=' start sending', font= ('official script', 15), command=send) button1.grid (row=3, column=0) button2 = Button (root, text=' exit Program', font= ('official script', 15) Command=root.quit) button2.grid (row=3, column=1) root.mainloop () so far On the "Python how to make automatic on-screen comment Mini Program" study is over, I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report