Python 如果用户在最后这么说,如何让脚本重新启动?

Python 如果用户在最后这么说,如何让脚本重新启动?,python,python-3.x,python-3.7,Python,Python 3.x,Python 3.7,我已经做了一个小程序,它可以从雅虎抓取你想要的任何关键字或短语的链接。我在最后添加了一个输入,询问用户是否希望输入更多的术语和获取更多的链接(基本上,在不退出程序的情况下重新启动程序,如果需要执行多个关键字,则再次单击)。如何使代码重新启动 import bs4 import requests import time import lxml from colorama import Fore, init init() print(Fore.RED + "▓██ ██▓ ▄▄▄ █

我已经做了一个小程序,它可以从雅虎抓取你想要的任何关键字或短语的链接。我在最后添加了一个输入,询问用户是否希望输入更多的术语和获取更多的链接(基本上,在不退出程序的情况下重新启动程序,如果需要执行多个关键字,则再次单击)。如何使代码重新启动

import bs4
import requests
import time
import lxml
from colorama import Fore, init
init()
print(Fore.RED + "▓██   ██▓ ▄▄▄       ██░ ██  ▒█████   ▒█████       ██████  ██▓    ▄▄▄  ░▒████   ██▓▓█████  ██▀███  ")
print(" ▒██  ██▒▒████▄    ▓██░ ██▒▒██▒  ██▒▒██▒  ██▒   ▒██    ▒ ▓██▒   ▒████▄    ▒██  ██░░█   ▀ ▓██ ▒ ██▒")
print("  ▒██ ██░▒██  ▀█▄  ▒██▀▀██░▒██░  ██▒▒██░  ██▒   ░ ▓██▄   ▒██░   ▒██  ▀█▄   ▒██ ██░▒███   ▓██ ░▄█ ▒")
print("  ░ ▐██▓░░██▄▄▄▄██ ░▓█ ░██ ▒██   ██░▒██   ██░     ▒   ██▒▒██░   ░██▄▄▄▄██  ░ ▐██▓░▒██  ▄ ▒██▀▀█▄  ")
print("  ░ ██▒▓░ ▓█   ▓██▒░▓█▒░██▓░ ████▓▒░░ ████▓▒░   ▒██████▒▒░██████▒▓█   ▓██▒ ░ ██▒▓░░█████▒░██▓ ▒██▒")
print("   ██▒▒▒  ▒▒   ▓▒█░ ▒ ░░▒░▒░ ▒░▒░▒░ ░ ▒░▒░▒░    ▒ ▒▓▒ ▒ ░░ ▒░▓  ░▒▒   ▓▒█░  ██▒▒▒ ░░ ▒░ ░░ ▒▓ ░▒▓░")
print(" ▓██ ░▒░   ▒   ▒▒ ░ ▒ ░▒░ ░  ░ ▒ ▒░   ░ ▒ ▒░    ░ ░▒  ░ ░░ ░ ▒  ░ ▒   ▒▒ ░▓██ ░▒░  ░ ░  ░  ░▒ ░ ▒░")
print(" ▒ ▒ ░░    ░   ▒    ░  ░░ ░░ ░ ░ ▒  ░ ░ ░ ▒     ░  ░  ░    ░ ░    ░   ▒   ▒ ▒ ░░     ░     ░░   ░ ")
print(" ░ ░           ░  ░ ░  ░  ░    ░ ░      ░ ░           ░      ░  ░     ░  ░░ ░        ░  ░   ░     ")
print(" ░ ░                                                                      ░ ░                     ")
print("")
print("The Link Scraper For Yahoo")
print("")
print("Created By IronKey | V1.0 beta | python 3.7.4")
print("")
your_keyword = input("enter your dork or search term : ")
print("")

linkNumber = int(  input("link depth? ") ) # <--- Raises Error if input is not a number

lst = []
# https://search.yahoo.com/search?p=bruhmoment&pz=10&ei=UTF-8&fr=yfp-t&bct=0&fp=1&b=31&pz=10&bct=0&xargs=0
link = "https://search.yahoo.com/search?p={}&pz=10&ei=UTF-8&fr=yfp-t&bct=0&fp=1&b={}&bct=0&xargs=0"
for i in range( linkNumber ): 
    lst.append( link.format( your_keyword, 1 + (i+1)*10 ) ) 
print("")
print( lst )
print("")
print("beginning search... ")
print("")
for x in tqdm(range(i)):
    time.sleep(0.0001)
for i in lst:
    source = requests.get(i)
    bs4call = bs4.BeautifulSoup(source.text, "lxml")
    links = bs4call.findAll('a', {'class':'ac-algo fz-l ac-21th lh-24'})
    for link in links:
        with open('links.txt', 'a') as out:
            out.write(str(link['href']) + "\n")


print("links scraped and saved to file : links.txt")
print("")
deepParseInput = input("would you like to run more dorks? :  ")
print("")
if deepParseInput == "y" or deepParseInput == "Y":
    reload()
else:
    print("I really hope you liked my program! Bye Bye - IronKey")
print("")
input("Press ENTER to leave the program --> ")
#for link in links:
  #with open('baselinks.txt', 'a') as out:
    #out.write(str(link['href']) + "\n")
print("")
deepParseInput = input("would you like to run more dorks? :  ")
print("")
if deepParseInput == "y" or deepParseInput == "Y":
    #restart the program
else:
    print("I really hope you liked my program! Bye Bye - IronKey")
print("")
input("Press ENTER to leave the program --> ")

导入bs4
导入请求
导入时间
导入lxml
从colorama导入前,初始化
init()
打印(前红色+”▓██   ██▓ ▄▄▄       ██░ ██  ▒█████   ▒█████       ██████  ██▓    ▄▄▄  ░▒████   ██▓▓█████  ██▀███  ")
打印(“▒██  ██▒▒████▄    ▓██░ ██▒▒██▒  ██▒▒██▒  ██▒   ▒██    ▒ ▓██▒   ▒████▄    ▒██  ██░░█   ▀ ▓██ ▒ ██▒")
打印(“▒██ ██░▒██  ▀█▄  ▒██▀▀██░▒██░  ██▒▒██░  ██▒   ░ ▓██▄   ▒██░   ▒██  ▀█▄   ▒██ ██░▒███   ▓██ ░▄█ ▒")
打印(“░ ▐██▓░░██▄▄▄▄██ ░▓█ ░██ ▒██   ██░▒██   ██░     ▒   ██▒▒██░   ░██▄▄▄▄██  ░ ▐██▓░▒██  ▄ ▒██▀▀█▄  ")
打印(“░ ██▒▓░ ▓█   ▓██▒░▓█▒░██▓░ ████▓▒░░ ████▓▒░   ▒██████▒▒░██████▒▓█   ▓██▒ ░ ██▒▓░░█████▒░██▓ ▒██▒")
打印(“██▒▒▒  ▒▒   ▓▒█░ ▒ ░░▒░▒░ ▒░▒░▒░ ░ ▒░▒░▒░    ▒ ▒▓▒ ▒ ░░ ▒░▓  ░▒▒   ▓▒█░  ██▒▒▒ ░░ ▒░ ░░ ▒▓ ░▒▓░")
打印(“▓██ ░▒░   ▒   ▒▒ ░ ▒ ░▒░ ░  ░ ▒ ▒░   ░ ▒ ▒░    ░ ░▒  ░ ░░ ░ ▒  ░ ▒   ▒▒ ░▓██ ░▒░  ░ ░  ░  ░▒ ░ ▒░")
打印(“▒ ▒ ░░    ░   ▒    ░  ░░ ░░ ░ ░ ▒  ░ ░ ░ ▒     ░  ░  ░    ░ ░    ░   ▒   ▒ ▒ ░░     ░     ░░   ░ ")
打印(“░ ░           ░  ░ ░  ░  ░    ░ ░      ░ ░           ░      ░  ░     ░  ░░ ░        ░  ░   ░     ")
打印(“░ ░                                                                      ░ ░                     ")
打印(“”)
打印(“雅虎的链接刮刀”)
打印(“”)
打印(“由IronKey | V1.0 beta版| python 3.7.4版创建”)
打印(“”)
您的_关键字=输入(“输入您的dork或搜索词:”)
打印(“”)

linkNumber=int(输入(“链接深度?”)#一个好主意是将代码转换为函数,并在用户想要重新启动程序时调用该函数。

将整个代码包装在
中,而True:
循环中,如果用户输入“n”,打破循环,否则让它继续从顶部循环。我做的每一行代码都要点击tab:3,但非常感谢!