简体   繁体   English

如何 24/7 全天候运行 selenium Web 驱动程序脚本

[英]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.好的,这是我的两个建议。

  1. Run your webdriver in headless mode.在无头模式下运行您的网络驱动程序。 Keeps it from using an open window, and lessens the resource draw.防止它使用打开的窗口,并减少资源消耗。

  2. 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.

相关问题 如何让 python selenium webdriver 脚本 24/7 全天候运行? - How can I have a python selenium webdriver script run 24/7? 如何使用 selenium webdriver 24/7 运行 python 脚本 - How to run a python script 24/7 with selenium webdriver Selenium Web驱动程序:如何单击按钮? - Selenium web driver: How do I click on the button? Selenium Web驱动程序:如何从元素获取URL? - Selenium Web Driver: How do I get a url from an element? 为什么我会收到此错误:AttributeError: 'Fetch_Info' object has no attribute 'driver' 当我运行我的 selenium_web.py 脚本时 - Why do I get this error :AttributeError: 'Fetch_Info' object has no attribute 'driver' when I run my selenium_web.py script 如何修复 selenium web 驱动程序和空列表上的列表索引超出范围 - How do I fix list index out of range on selenium web driver and empty list 如何一一浏览链接列表,然后使用 selenium(driver.get) 抓取数据? - How do I run through a list of links one by one and then scrape data using selenium(driver.get)? 如何在AWS Lambda 24/7上运行python脚本 - How can I run my python script on AWS lambda 24/7 因此,当我通过jenkins运行python硒脚本时,应该如何编写“ driver = webdriver.Chrome()”? - So when I run my python selenium script through jenkins, how should I write the 'driver = webdriver.Chrome()'? 如何在Java Web应用程序中运行Python脚本? - How do I run a Python Script in a Java web application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM