Web 进程在启动后 60 秒内无法绑定到 $PORT Python Selenium
Web process failed to bind to $PORT within 60 seconds of launch Python Selenium
运行 在 Heroku
上刮硒。它 运行s 但每 6-7 秒后它就会崩溃并出现此错误
2021-06-24T15:33:07.835601+00:00 heroku[web.1]: Error R10 (Boot
timeout) -> Web process failed to bind to $PORT within 60 seconds of
launch 2021-06-24T15:33:07.884148+00:00 heroku[web.1]: Stopping
process with SIGKILL 2021-06-24T15:33:08.022511+00:00 heroku[web.1]:
Process exited with status 137 2021-06-24T15:33:08.119687+00:00
heroku[web.1]: State changed from starting to crashed
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)?
我在 Procfile
中使用 web
。我将其更改为 worker
并且有效。
运行 在 Heroku
上刮硒。它 运行s 但每 6-7 秒后它就会崩溃并出现此错误
2021-06-24T15:33:07.835601+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch 2021-06-24T15:33:07.884148+00:00 heroku[web.1]: Stopping process with SIGKILL 2021-06-24T15:33:08.022511+00:00 heroku[web.1]: Process exited with status 137 2021-06-24T15:33:08.119687+00:00 heroku[web.1]: State changed from starting to crashed
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)?
我在 Procfile
中使用 web
。我将其更改为 worker
并且有效。