About using Python to send messages to QQ friends (the role of the crawler----when the program executed or error unlimited to their QQ send messages, until closed)

Source: Internet
Author: User
Tags win32

Previously saw some small programs on the Internet, after the processing of things will automatically send QQ messages, but have been confused is the principle of explanation. Also on the Internet to find some of the Python landing QQ sent messages text, but are too complex. Today by chance to see an article, is to use Python call Win32 interface to send QQ message, feel good, first record down, in the future will certainly use these gadgets.
Send QQ message request has been landing QQ, and QQ window is independent, now the new version of QQ is generally all chat window aggregation together, so to set the QQ window separation, or the need to send a message to separate the window.
On the code bar.
#The principle is to put the text you want to send to the Clipboard, and then send the Clipboard contents to the QQ window#after the analog button sends the ENTER key to send the messageImportWin32guiImportWin32conImportWin32clipboard as WdefGetText ():"""get Clipboard text"""W.openclipboard () d=W.getclipboarddata (Win32con. Cf_unicodetext) W.closeclipboard ()returnDdefSetText (astring):"""set Clipboard text"""W.openclipboard () W.emptyclipboard () W.setclipboarddata (Win32con. Cf_unicodetext, astring) W.closeclipboard ()defsend_qq (to_who, msg):"""Send QQ message TO_WHO:QQ message receiver MSG: message to be sent"""    #write a message to the ClipboardsetText (msg)#get QQ window handleQQ =Win32gui. FindWindow (None, to_who)#post Clipboard messages to QQ formWin32gui. SendMessage (QQ, 258, 22, 2080193) Win32gui. SendMessage (QQ,770, 0, 0)#Simulate Press ENTERWin32gui. SendMessage (QQ, Win32con. Wm_keydown, Win32con. Vk_return, 0) Win32gui. SendMessage (QQ, Win32con. Wm_keyup, Win32con. Vk_return, 0)#Testto_who='XXX'msg='This is a test message .'send_qq (to_who, msg)

Special Note: to_who is filled in the name of the Chat window, not the QQ number. (That is, the network name or note name, the specific can also be viewed in the Task Manager)

Analog keys

Python can do a variety of interactions through Win32 and Windows, and an article on the Web is an example of a batch operation file with the same principles as the Key wizard. Just a lot of parameters do not understand. Like the above to send QQ message example, originally wanted to change the method, skip the Clipboard This step, but how to change all not, and then try again.

Reference:

http://blog.csdn.net/dahuae/article/details/43969175
http://blog.csdn.net/seele52/article/details/17504925
http://lixxu.iteye.com/blog/417218
http://www.codeweblog.com/%E7%94%A8pywin32%E5%AE%9E%E7%8E%B0windows%E6%A8%A1%E6%8B%9F%E9%BC%A0%E6%A0%87%E5%8F% 8a%e9%94%ae%e7%9b%98%e5%8a%a8%e4%bd%9c/

Reproduced above from http://blog.csdn.net/suzyu12345/article/details/52934328

What can we do with this feature for crawlers? The first thing I thought of was the ability to monitor the crawler's progress. For example, if the crawl time is too long, two days a day or longer, we can not always stare at the screen, this time we will be able to use this feature.

When the bot end or the error stops, we can send our own QQ message, the tip of our crawler end.

Using the pipelines.py file in Scrapy, the following method:

def Close_spider (self,spider):

When the program is finished, call the above code, prompting us to end the crawler, to achieve the purpose of monitoring

About using Python to send messages to QQ friends (the role of the crawler----when the program executed or error unlimited to their QQ send messages, until closed)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.