[英]How to take output of function and use as input of another function python?
More specifically my function grabs all the domains in a my database table and returns them. 更具体地说,我的函数获取数据库表中的所有域并返回它们。 I want to know how to input these domains into another function that will run the Kali Linux tool URLcrazy for each of the domains in that table.
我想知道如何将这些域输入到另一个函数中,该函数将对该表中的每个域运行Kali Linux工具URLcrazy。
For example my function that outputs these: 例如我的函数输出以下内容:
google.com google.com
yahoo.com yahoo.com
Here is the function: 这是函数:
def grab_domains():
try:
db = pymysql.connect(host="localhost",
user="root", passwd="root",
db="typosquat")
except ConnectionAbortedError as e:
print(e, "\n")
temp = ""
cursor = db.cursor()
cursor.execute('SELECT name From domains')
for rows in cursor.fetchall():
for entries in rows:
temp += entries
domains = entries[0:]
print(domains)
return temp
Here is the output: 这是输出:
google.com google.com
yahoo.com yahoo.com
How do I write another function that will run the script URLcrazy on each of these domains? 如何编写另一个将在每个域上运行脚本URLcrazy的函数? Assuming all scripts are in same file location.
假设所有脚本都在同一文件位置。
This is all I have I cant figure out how to run it for each domain, only know how to for a single output. 这就是我无法弄清楚如何为每个域运行它的全部,只知道如何为单个输出运行。
def run_urlcrazy():
np = os.system("urlcrazy " + grab_domains())
print(np)
return np
How to I get this function to run URLcrazy for each domain?^^ 我如何获得此功能以为每个域运行URLcrazy?^^
This is my first post ever on stack overflow let me know what I can do to improve it and help me with question if possible! 这是我有史以来第一篇关于堆栈溢出的文章,让我知道我可以做些什么来改进它,并在可能的情况下帮助我解决问题! Thanks
谢谢
You'll need a loop: 您将需要一个循环:
def run_urlcrazy():
ret_vals = []
for domain in grab_domains():
np = os.system("urlcrazy " + domain)
ret_vals.append(np)
return ret_vals
I recommend a for
loop because it can efficiently iterate over whatever your function returns. 我建议使用
for
循环,因为它可以有效地迭代函数返回的任何内容。
You'll need to make a minor modification to your grab_domains()
function as well: 您还需要对
grab_domains()
函数进行较小的修改:
temp = []
cursor = db.cursor()
cursor.execute('SELECT name From domains')
for rows in cursor.fetchall():
for entries in rows:
domains = entries[0:]
temp.extend(domains)
return temp
Now, your function returns a list of domains. 现在,您的函数将返回域列表。 You can iterate over this.
您可以对此进行迭代。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.