5 个 Python 自动化脚本
Python测试开发
共 4963字,需浏览 10分钟
·
2023-09-14 15:57
介绍
Python是一种功能强大的编程语言,可用于自动执行各种任务。无论您是开发小型项目还是大型企业应用程序,Python 都可以帮助您节省时间并简化您的工作流程。
Python是一种伟大的语言,因为它的语法非常简单。10行Python代码完成的工作,在Javascript或C++这样的语言中,需要20行代码。下面是一个简单的 Web 请求的示例:
import requests
r = requests.get("https://www.python.org")
print(r.status_code)
print(r.text)
fetch(“https://www.python.org")
.then(res => {
if(res.ok) {
return res.text();
} else {
throw new Error(“HTTP error, status = “ + res.status);
}
})
.then(text => {
console.log(text);
})
.catch(error => {
console.log(error);
});
网址缩短器
importpyshorteners
s = pyshorteners.Shortener(api_key="YOUR_KEY")
long_url =input("Enter the URL to shorten: ")
short_url = s.bitly.short(long_url)
print("The shortened URL is: "+ short_url)
创建伪信息
import pandas as pd
from faker import Faker
# Create object
fake = Faker()
# Generate data
fake.name()
fake.text()
fake.address()
fake.email()
fake.date()
fake.country()
fake.phone_number()
fake.random_number(digits=5)
# Dataframe creation
fakeDataframe = pd.DataFrame({‘date’:[fake.date() for i in range(5)],
‘name’:[fake.name() for i in range(5)],
‘email’:[fake.email() for i in range(5)],
‘text’:[fake.text() for i in range(5)]})
print(fakeDataframe)
优酷视频下载器
from pytube import YouTube
link = input("Enter a youtube video's URL") # i.e. https://youtu.be/dQw4w9WgXcQ
yt = Youtube(link)
yt.streams.first().download()
print("downloaded", link)
北约音标加密器
def encrypt_message(message):
nato_alphabet = {
‘A’: ‘Alfa’, ‘B’: ‘Bravo’, ‘C’: ‘Charlie’, ‘D’: ‘Delta’,
‘E’: ‘Echo’, ‘F’: ‘Foxtrot’, ‘G’: ‘Golf’, ‘H’: ‘Hotel’,
‘I’: ‘India’, ‘J’: ‘Juliet’, ‘K’: ‘Kilo’, ‘L’: ‘Lima’,
‘M’: ‘Mike’, ’N’: ‘November’, ‘O’: ‘Oscar’, ‘P’: ‘Papa’,
‘Q’: ‘Quebec’, ‘R’: ‘Romeo’, ‘S’: ‘Sierra’, ‘T’: ‘Tango’,
‘U’: ‘Uniform’, ‘V’: ‘Victor’, ‘W’: ‘Whiskey’, ‘X’: ‘Xray’,
‘Y’: ‘Yankee’, ‘Z’: ‘Zulu’
}
encrypted_message = “”
# Iterate through each letter in the message
for letter in message:
# If the letter is in the dictionary, add the corresponding codeword to the encrypted message
if letter.upper() in nato_alphabet:
encrypted_message += nato_alphabet[letter.upper()] + “ “
# If the letter is not in the dictionary, add the original letter to the encrypted message
else:
encrypted_message += letter
return encrypted_message
message = "Hello World"
encrypted_message = encrypt_message(message)
print("Encrypted message: ", encrypted_message)
社交媒体登录自动化
from selenium import webdriver
driver = webdriver.Firefox()
driver.get(“https://www.facebook.com/")
# Find the email or phone field and enter the email or phone number
email_field = driver.find_element_by_id(“email”)
email_field.send_keys(“your_email_or_phone”)
# Find the password field and enter the password
password_field = driver.find_element_by_id(“pass”)
password_field.send_keys(“your_password”)
# Find the login button and click it
login_button = driver.find_element_by_id(“loginbutton”)
login_button.click()
评论
图片
表情
视频
全部评论