常用Python脚本毕业生必看

如题所述

你每天都会用到的Python自动化脚本

5个Python自动化脚本

1、网址缩短器

import py shorten ers

s=py shorten ers.Short ener(api_key="YOUR_KEY")

long_url=input("Enter the URL to shorten:“)

short_url=s.bit ly.short(long_url)

print("The shortened URL is:"+short_url)

在URL缩短方面, Py shorten ers库是我最喜欢的库之一, 可用于各种项目。大多数链接缩短器都需要一个API密钥, 但除非您预计会有数十万个请求,否则它们通常是免费的。我发现像Bit.ly, Adf.ly和Tinyurl这样的API非常适合SaaS应用程序和Telegram机器人。

2、创建伪信息

import pandas a spd from faker import Faker

#Createobject fake=Faker()

#Generatedata fake.name()

fake.text()

fake.address()fake.email()

fake.date()

fake.country()fake.phone_number()

fake.random_number(digits=5)

#Dato frame creo tion fake Data frame=pd.Data Frame({‘date':[fake.date() for i in range(5) ] ,‘name’:[fake.name() for i in range(5) ] ,femail':[fake.email() for i in range(5) ] ,“text':[fake.text() for i in range(5) ] } )print(fake Data frame)

如果您需要创建一个假人(伪造的角色),这个伪造者库为您提供了一个伪造者类,可以自动生成整个假人。此脚本创建几个不同的人并将他们存储在数据Frame中, 这是一个稍微复杂的概念。如果我不得不向不太信任的网站提供信息,或者如果我不想其他人追溯到我的任何信息,我会使用这些假人信息。

3、优酷视频下载器

from py tube import YouTube

link=input("Enter a youtube video's URL") #i.e,https://youtu.be/dQw4w9llgXcQ

yt=Youtube(link)

yt.streams.first() .download()

print("downloaded", link)

很简单。它使用py tube库将您提供的任何链接转换为文件, 然后下载它。使用五行代码且没有API速率限制, 您可以将其与另一个脚本结合使用来转录视频并使用情绪分析来确定视频包含的内容类型。

4、社交媒体登录自动化

from selenium import web driver

driver=web driver.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(“pass")password_field.send_keys(“your_password”)

#Find the login button and click it

login_button=driver.find_element_by_id(“login button”)login_button.click()

此代码利用Selenium, 一个流行的Web自动化库。它打开一个Web浏览器, 并根据代码中给出的各种命令进行导航。在这个特定的代码块中, 浏览器将跳转到Facebook, 并在网页上找到要修改的特定元素。在这里,我们在电子邮件和密码字段中输入某些字符,然后单击"登录"按钮。如果提供了有效的凭据,这将自动登录用户。

5、北约音标加密器

def encrypt_message(message) :

nato_alphabet={

‘A':‘Alfa', ‘B':‘Bravo’, ‘C':f Charlie', ‘D':‘Delta',

“E':“Echo', “F':“Foxtrot’, “G':“Golf, “H:Hotel',

“I':“India', 勺':“Juliet’, “K”:“Kilo”, ‘L”:“Lima',

“M:“Mike', 'NP:November', “0’; “Oscar', “P':‘Papa',

“Q':“Quebec', “R':Romeo’, ‘S':“Sierra', T':“Tango’,

UP:“Uniform', ‘V”:‘Victor', “W:whiskey’, ‘X:“Xray',

‘Y':f Yankee’, ‘Z’:“Zulu’

encrypted_message w

#Iterate through each Letter in the message

for letter in message:

#I the Letter is in the diction or y, add the corresponding codeword to the encrypted messag

if letter.upper() in nato_alphabet:

encrypted_message+=nato_alphabet[letter.upper() ] +“n

#I the Letter is not in the dictionary, add the original Letter to the encrypted message

else:

encrypted_message+=letter

return encrypted_message

message="HelloWorld"

encrypted_message=encrypt_message(message)

print("Encrypted message:", encrypted_message)

温馨提示:答案为网友推荐,仅供参考
第1个回答  2023-06-14

你每天都会用到的Python自动化脚本

5个Python自动化脚本

1、网址缩短器

在URL缩短方面, Py shorten ers库是我最喜欢的库之一, 可用

于各种项目。大多数链接缩短器都需要一个API密钥, 但除非您

预计会有数十万个请求,否则它们通常是免费的。我发现像

Bit.ly, Adf.ly和Tinyurl这样的API非常适合SaaS应用程序

和Telegram机器人。

2、创建伪信息

如果您需要创建一个假人(伪造的角色),这个伪造者库为您提

供了一个伪造者类,可以自动生成整个假人。此脚本创建几个不

同的人并将他们存储在数据Frame中, 这是一个稍微复杂的概念

。如果我不得不向不太信任的网站提供信息,或者如果我不想其

他人追溯到我的任何信息,我会使用这些假人信息。

3、优酷视频下载器

很简单。它使用py tube库将您提供的任何链接转换为文件, 然

后下载它。使用五行代码且没有API速率限制, 您可以将其与另

一个脚本结合使用来转录视频并使用情绪分析来确定视频包含的

内容类型。

4、社交媒体登录自动化

此代码利用Selenium, 一个流行的Web自动化库。它打开一

个Web浏览器, 并根据代码中给出的各种命令进行导航。在这

个特定的代码块中, 浏览器将跳转到Facebook, 并在网页上找

到要修改的特定元素。在这里,我们在电子邮件和密码字段中输

入某些字符,然后单击"登录"按钮。如果提供了有效的凭据,这

将自动登录用户。

5、北约音标加密器




相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网