我已经做了一个小程序,从雅虎刮链接与任何关键字或短语你想要的,因为你想要的。我在末尾添加了一个输入,询问用户是否想要输入更多的术语和刮取更多的链接(基本上是在不退出的情况下重新启动程序,如果需要执行多个关键字,则再次单击)。如何使代码重新启动
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 --> ")
一个好主意是将代码转换成一个函数,并在用户想要重新启动程序时调用该函数
相关问题 更多 >
编程相关推荐