Python webbrowser module and sendkeys Module

Source: Internet
Author: User

When I suddenly encountered a problem at work today, I tried to think about things as the leaders said.CodeI forgot about it. I thought of using thunder to download some things. Thunder didn't know what happened, but I knew that he was monitoring the Computer Browser. So when I wanted to download something, you can get an address that complies with the thunder protocol. You can use the webbrowser module to open this address and call thunder to do my own thing.

 
Import webbrowser

Webbrowser. Open ('Http://www.google.com.hk/')

I am using a Windows operating system. This module is actually simpler and more primitive for us to use:

 If sys. platform [: 3] = "win": Class windowsdefault (basebrowser): def open (self, URL, new = 0, autoraise = 1): Try: OS. startfile (URL) failed t windowserror: # [error 22] No application is associated with the specified # file for this operation: '
  
    'Return false else: return true _ tryorder = [] _ browsers ={}# first try to use the default Windows browser register ("Windows-Default", windowsdefault) # detect some common Windows browsers, fallback to IE iexplore = OS. path. join (OS. environ. get ("ProgramFiles", "C: \ Program Files"), "Internet Explorer \ iw.e. EXE ") for browser in (" Firefox "," Firebird "," SeaMonkey "," Mozilla "," Netscape "," Opera ", istme): If _ iscommand (browser): Register (browser, none, backgroundbroister (browser) 
  

The operating system is different. There will be differences here. In fact, the most useful one is the OS. startfile (URL) can also obtain the effect of webbrower module open, but we recommend webbrower because it is more compatible.

Think of it here, with the keyboard operation module, sendkeys, and mouse simulation operations, you can certainly make quite good things.

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.