我从我的 instagram bot python 脚本创建了一个 exe,它不会再保存新条目。我想知道将此脚本编译为可分发且独立的 .exe 文件的最佳方法是什么。我尝试了 pyinstaller 但它只打开 cmd 一秒钟然后关闭。我使用 autopy 来编译当前正在运行的 exe。在此处输入图像描述
def save_username():
Username_info = entry2.get()
Password_info = entry.get()
Comment_info = entry3.get()
Tags_info = entry4.get()
print(Username_info)
print(Password_info)
print(Tags_info)
print(Comment_info)
file = open("creds.py", "w")
file.write("user1 = '" + Username_info + "' ")
file.write("\n")
file.write("passw = '" + Password_info + "' ")
file.write("\n")
file.write("comments = [" + Comment_info + "]")
file.write("\n")
file.write("tags = '" + Tags_info + "' ")
file.close()
while count < 5:
def run():
class Instagram():
def __init__(self, user1, passw):
self.username = user1
self.password = passw
options = Options()
options.add_experimental_option("excludeSwitches", ["enable-logging"])
# options.add_argument("--headless")
self.browser = webdriver.Chrome("chromedriver",options=options)
self.browser.set_window_size(800, 900)
def close_browser(self):
self.browser.close()
self.browser.quit()
def login(self):
browser = self.browser
browser.get('https://www.instagram.com')
time.sleep(random.randrange(3, 5))
username_input = browser.find_element_by_name('username')
username_input.clear()
username_input.send_keys(user1)
index = random.randint(0, len(tags) - 1)
time.sleep(random.randrange(2, 4))
password_input = browser.find_element_by_name('password')
password_input.clear()
password_input.send_keys(passw)
time.sleep(random.randrange(1, 2))
password_input.send_keys(Keys.ENTER)
time.sleep(random.randrange(3, 5))
self.browser.find_element_by_xpath("//button[contains(text(), 'Not Now')]").click() # clicking 'not now btn'
sleep(2)
self.browser.find_element_by_xpath("//button[contains(text(), 'Not Now')]").click() # clicking 'not now btn'
while count < 5:
self.browser.get('https://www.instagram.com/explore/tags/' + (random.choice(tags.split())))
sleep(12)
first_thumbnail = self.browser.find_element_by_xpath(
"/html/body/div[1]/section/main/article/div[1]/div/div/div[1]/div[1]/a")
first_thumbnail.click()
sleep(12)
try:
self.browser.find_element_by_class_name('RxpZH').click()
sleep(12)
self.browser.find_element_by_xpath("//textarea[@placeholder='Add a comment…']").send_keys(random.choice(comments))
sleep(12)
self.browser.find_element_by_xpath("//button[@type='submit']").click()
sleep(12)
except Exception as e:
print("No Comment Section")
bot = Instagram(config.username, config.password)
bot.login()
if config.tags == 'tag':
bot.comment_by_tags(config.tags, config.comments, config.amount, config.delay)
def discord():
class disk():
browser = webdriver.Chrome("chromedriver")
browser.set_window_size(800, 900)
browser.get('https://discord.gg/tGwXPgAEeN')
root = Tk()
root.title("B.E.O InstaBotV.1")
w = Canvas(root,
width=canvas_width,
height=canvas_height,)
my_image2 = ImageTk.PhotoImage(Image.open("br.png"))
my_label2= Label(root, image=my_image2)
w.create_image(0,0,anchor=NW,image=my_image2)
w.pack()
#canvas_1 = Canvas(width = 100, height = 100, bg = "blue")
#canvas_1.place(relx=0.4, rely=0.05)
#gif = PhotoImage(file = "me.gif")
#canvas_1.create_image(0, 0, image = gif, anchor = N)
#frame= tk.Frame(root, bg='#80c1ff', bd=5)
#frame.place(relwidth=2, relheight=0.25, anchor= 'n')
#entry = Entry(textvariable= entry, width="30")
#entry.place(relwidth=0.65, relheight=1)
#Username Label
label = Label(root,
text="Enter Username",
bg="red")
label.place(relx=0.1, rely=0.08,relwidth=0.25, relheight=0.03)
#Username Entry
entry2 = Entry(textvariable=user1)
entry2.place(relx=0.1, rely=0.1,relwidth=0.25, relheight=0.05)
entry2.insert(0, user1)
#pass Label
label = Label(root,
text="Enter Password",
bg="red")
label.place(relx=0.1, rely=0.18,relwidth=0.25, relheight=0.03)
#pass Entry
entry = Entry(textvariable=passw)
entry.place(relx=0.1, rely=0.2,relwidth=0.25, relheight=0.05)
entry.insert(0, passw)
#Comments Label
label = Label(root,
text="Enter Comments",
bg="red",font =40)
label.place(relx=0.4, rely=0.08,relwidth=0.50, relheight=0.03)
#Comments Entry
entry3 = Entry(textvariable=comments, justify= CENTER)
entry3.place(relx=0.4, rely=0.1,relwidth=0.50, relheight=.2)
entry3.insert(0, comments)
#Tags Label
label = Label(root,
text="Enter Hashtags",
bg="red")
label.place(relx=0.1, rely=0.28,relwidth=0.25, relheight=0.03)
#Tags Entry
entry4 = Entry(textvariable=tags)
entry4.place(relx=0.1, rely=0.3,relwidth=0.25, relheight=0.05)
entry4.insert(0, tags)
#SAVE BUTTON
button2 = tk.Button(root, text="Save Info", font=40, command=save_username,background= "red")
button2.place(relx=0.1, rely=0.4,relwidth=0.25, relheight=0.05)
#RUN BUTTON
button =Button(root, text='Run B.E.O InstaBot', command=run, background= "red")
button.place(relx=0.1, rely=0.48,relwidth=0.25, relheight=0.1)
#DISCORD BUTTON
button3 =Button(root, text='Join B.E.O Discord Server', command=discord, background= "red", font= 50)
button3.place(relx=0.4, rely=0.48,relwidth=0.5, relheight=0.1)
label = Label(root,
text=" After Saving Please Restart App. If any other issues occur restart the bot.\n This Bot Comments on 1 Post Per Minute, Which Is Instagram's Limit. For\n help join the discord below.",
bg="red", fg= "#260026", font=40, borderwidth=4, relief="sunken")
label.place(relx=0.4, rely=0.35,relwidth=0.5, relheight=0.11)
label = Label(root,
text="Comment Format 'comment', 'comment ', 'comment' ", font= 40,
bg="red", fg="#260026")
label.place(relx=0.4, rely=0.3,relwidth=0.50, relheight=0.03)
label = Label(root,
text="Add Spaces Between Tags", font= 40,
bg="red")
label.place(relx=0.1, rely=0.35,relwidth=0.25, relheight=0.03)
root.mainloop()
root.destroy()