AWS在没有API的页面上在此处宣布“中断频率”: https://aws.amazon.com/ec2/spot/instance-advisor/
我需要按计划获取弗吉尼亚州的所有类型(255件)。我怎样才能做到这一点?
我通过使用selenium和Python爬行页面来解决它。您可以在docker中运行以下脚本,它将创建aws-spot-instance.txt
pwd。
您可以region = 'US East (N. Virginia)'
在脚本中更改区域。
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
options = Options()
options.add_argument("--headless") # Runs Chrome in headless mode.
options.add_argument('--no-sandbox') # # Bypass OS security model
options.add_argument('start-maximized')
options.add_argument('disable-infobars')
options.add_argument("--disable-extensions")
options.add_argument('--disable-gpu')
region = 'US East (N. Virginia)'
driver = webdriver.Chrome(chrome_options=options)
driver.get("https://aws.amazon.com/ec2/spot/instance-advisor")
element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, ".dropdown-container.aws-dropdown-region.dropdown-built")))
element.click()
driver.find_element_by_xpath("//span[text()='%s']" %region).click()
driver.find_element_by_css_selector(".aws-spot-advisor-button-expand.button").click()
table_data = driver.find_element_by_css_selector(".table.table-striped").text
fw = open('aws-spot-instance.txt', "w")
fw.write(table_data)
fw.close()
保存此脚本aaws.py
并运行以下命令:
docker pull gunesmes/python-selenium-behave-page-object-docker
docker run --rm --name aws -v $PWD:/project gunesmes/python-selenium-behave-page-object-docker bash -c "python3 aws.py"
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句