If you want to be laughed at by Douyin, opening a web page is considered a hacker?

Hello everyone, my name is Zhu Xiaowu

Everyone will see similar videos when they are on Douyin: The marketing account can pretend to be a hacker by writing a few lines of code with txt notepad Barabala.


▲A single operation is as fierce as a tiger

Another example is the following. From a distance, the operation is as fierce as a tiger, but from a closer look, the code turns out to open a web page.


▲Open a webpage

After simply watching a few videos, I found that the most common routines used by "hacker" marketing accounts are dir/s start and exit do and loop.

The DOS command start is the command, which can start an exe program or a BAT batch script.

It is a relatively important command. The start command is a parallel command, which means that it can run multiple at the same time when running exe. Therefore, most of the tutorials for opening the computer version of WeChat also use start.

PS: You can actually open more WeChat without starting. In fact, you can select WeChat with the left mouse button, and then press the Enter key several times in a row.

Ok, let's go back to the previous picture, the marketing account uses batch commands to open the web page to pretend to be a hacker. And we, as a Python number, just took this opportunity to chat, what should we do if we open a web page with Python?

you

By referencing the os package, call the system method to call the system's browser program to open the URL

import os

os.system('"C:/Users/.../chrome.exe" https://cybermap.kaspersky.com/')

To test by yourself, remember to replace the above code with your actual program path and specific URL.

selenium

seleniumModules allow us to open a web browser and simulate any action, typically used for automated testing, crawling, or filling out forms, etc.

Enter the following command in the interactive environment:

from selenium import webdriver

driver = webdriver.Chrome(your_browser_path)
driver.get("https://cybermap.kaspersky.com/")

seleniumIn this way, a browser web page can be opened through the module, and subsequent operations can be continued, such as clicking buttons, filling out forms, scrolling progress bars, and so on.

web browser

Unlike selenium, a webbrowserlibrary is a built-in module.

If you want to execute the following command on the command line:

python -m webbrowser -t "https://cybermap.kaspersky.com/"

You will find that the system's default browser is automatically launched and the https://cybermap.kaspersky.com/web page is opened in the window.

[External link image transfer failed, the source site may have anti-leech mechanism, it is recommended to save the image and upload it directly (img-Y1b0gk8G-1662576353481) (https://typora-1300769465.cos.ap-beijing.myqcloud.com/typora_zhuxiao5 /automatically named 20220705221739.gif)]

In addition, there are two options for the parameters of the command script:

  • -n : Open a new window.
  • -t : Open a new tab.

If you call the module in Python webbrowser, the specific usage is as follows:

Enter the following command in the interactive environment:

webbrowser.open(url, new=0, autoraise=True)
webbrowser.open_new(url)
webbrowser.open_new_tab(url)

The new parameter indicates how to open the page:

  • new=1 : Open the webpage in a new browser window.
  • new=2 : Open the webpage in a new tab.

end

On the other hand, if you just want to open the browser and display the web page, choose webbrowserthe library. SeleniumModules are more suitable if you want to simulate user interaction for more actions . If the webbrowser module also wants to simulate user operations, it needs to be matched with pyautoguiother modules for click input, etc.

Recently, the new book that I spent two years writing has been listed, and it can be regarded as a summary of my three years of sharing Python knowledge on the CSDN blog!

" Learn Python Quickly: Easy Practice for Automated Office ", you can click the blue word to view the book details and support it.

Guess you like

Origin blog.csdn.net/zhuxiao5/article/details/126756980