-1

How to read python script in a website and run it in terminal ?

Example:

Script In pastebin.com:

import time
print('Hello World')
time.sleep(2)
exit()

Script In Terminal :

import requests
link = "https://pastebin.com/raw/script"
r = requests.get(link)
#Now How Run Script From Website ?

Please help me :)

Gabrielle
  • 19
  • 1

2 Answers2

0

The exec built-in function might be a way to execute the script with text.

import requests
link = "https://pastebin.com/raw/script"
r = requests.get(link)

#run the script
exec(r.text)

[EDIT] This method is unsafe and not recommanded. See this post: Why should exec() and eval() be avoided?

Lab
  • 196
  • 3
  • 18
0

Now you have the response in your code as r, and you want to first retrieve the text of the response:

response_text = r.text

Optionally, reset the encoding of the response text:

r.encoding = 'utf-8'

Now execute the content of the response with the Python built in exec method:

exec(response_text)
Gustav Rasmussen
  • 3,720
  • 4
  • 23
  • 53