[英]How do I run a selenium web driver script 24/7
How would I run a selenium web driver script 24/7 on the cloud?我将如何在云上 24/7 全天候运行 selenium Web 驱动程序脚本? I'm looking to run an instagram bot 24/7 without having to constantly open chrome and have pycharm open all the time.我希望 24/7 全天候运行 instagram bot,而不必经常打开 chrome 并始终打开 pycharm。
from selenium import webdriver
from time import sleep
driver = webdriver.Chrome(executable_path="/Users/benaiah/Downloads/chromedriver")
driver.get("https://instagram.com")
sleep(4)
driver.find_element_by_xpath("//input[@name=\"username\"]")\
.send_keys("username")
driver.find_element_by_xpath("//input[@name=\"password\"]")\
.send_keys("password")
driver.find_element_by_xpath('//button[@type="submit"]')\
.click()
sleep(4)
driver.find_element_by_xpath("//button[contains(text(), 'Not Now')]")\
.click()
driver.find_element_by_xpath("//button[contains(text(), 'Not Now')]")\
.click()
sleep(3)
for k in range(4):
for i in range(5):
driver.find_element_by_xpath('//button[text()="Follow"]')\
.click()
sleep(1)
driver.refresh()
Alright, so here would be my two suggestions.好的,这是我的两个建议。
Run your webdriver in headless mode.在无头模式下运行您的网络驱动程序。 Keeps it from using an open window, and lessens the resource draw.防止它使用打开的窗口,并减少资源消耗。
Don't use pycharm for execution, just run the script from your command prompt.不要使用 pycharm 执行,只需从命令提示符运行脚本。
If you run it "on the cloud" you'll have to get space on an online platform but most are not free.如果您在“云端”运行它,您将不得不在在线平台上获得空间,但大多数都不是免费的。 And some also have Terms of Service that this bot would violate.有些还具有此机器人会违反的服务条款。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.