【问题标题】:Web process failed to bind to $PORT within 60 seconds of launch Python SeleniumWeb 进程在 Python Selenium 启动后 60 秒内无法绑定到 $PORT
【发布时间】:2021-09-08 03:25:22
【问题描述】:

Heroku 上运行 selenium scrape。它运行,但每 6-7 秒后它会因此错误而崩溃

2021-06-24T15:33:07.835601+00:00 heroku[web.1]:错误 R10(启动 timeout) -> Web 进程未能在 60 秒内绑定到 $PORT 启动 2021-06-24T15:33:07.884148+00:00 heroku[web.1]:停止 使用 SIGKILL 2021-06-24T15:33:08.022511+00:00 heroku[web.1] 处理: 进程以状态 137 2021-06-24T15:33:08.119687+00:00 退出 heroku[web.1]:状态从开始变为崩溃

import os
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time
import requests
from PIL import Image




GOOGLE_CHROME_PATH = '/app/.apt/usr/bin/google_chrome'
CHROMEDRIVER_PATH = '/app/.chromedriver/bin/chromedriver'
PORT = int(os.environ.get('PORT', 13978))
options1 = Options()
options1.binary_location = os.environ.get('$GOOGLE_CHROME_BIN')
options1.add_argument("--headless")
options1.add_argument("--example-flag")
options1.add_argument('--no-sandbox')
options1.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome(executable_path=str(os.environ.get('CHROMEDRIVER_PATH')),options=options1)
driver.maximize_window()
driver.get('https://tryshowtime.com/c/spotlights')
print("On the page")
time.sleep(6)
i = 0
old_rest = set()
while True:
    try:
        driver.execute_script("window.scrollBy(0,3225)", "")
        time.sleep(12)
        images = driver.find_elements_by_xpath('//div[@class="relative"]//img')
        ans = set(images) - set(old_rest)  # Remove old elements

        for image in ans:
            i += 1
            link = image.get_attribute('src')
            print(f"got {i}th" + "link")
            img_f = requests.get(link, stream=True)
            with open(f'Image_{i}.jpg', 'wb') as f:
                f.write(img_f.content)
            img = Image.open(f'Image_{i}.jpg')
            if img.mode != 'RGB':
                img = img.convert('RGB')
            img_final = img.resize((1024,1024))
            img_final.save(f'Image_{i}.jpg')
            print("Image saved successfully")

        old_rest = images
    except:
        pass

看起来我没有设置port 对吗? Heroku 上的另一个爬虫也可以正常运行,但该爬虫仅在命令下运行,而不是连续运行。有人可以指导可能是什么问题吗?

INFO :-这可能不适用于 Heroku,因为它超出了 dyno's 内存 (512 MB)?

【问题讨论】:

  • 显示您的 proc 文件,您使用的是网络测功机吗?
  • @BeppeC 这解决了。我认为像你说的那样将其更改为worker 是必要的。

标签: python selenium heroku web-scraping


【解决方案1】:

我在我的Procfile 中使用了web。我将其更改为 worker 并且有效。

【讨论】:

    猜你喜欢
    • 2019-07-12
    • 2014-03-15
    • 1970-01-01
    • 1970-01-01
    • 2020-02-10
    • 1970-01-01
    • 2016-08-09
    • 2013-03-19
    相关资源
    最近更新 更多