x y通过screenshoot方法进行坐标

时间:2018-06-04 19:15:39

标签: python selenium

以下代码用于在交易视图网站上截取图表的屏幕截图。

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
import time

#MAMAarray = []
#FAMAarray = []

# example option: add 'incognito' command line arg to options
option = webdriver.ChromeOptions()
option.add_argument("--incognito")

# create new instance of chrome in incognito mode
browser = webdriver.Chrome(chrome_options=option)

# go to website of interest
browser.get("https://www.tradingview.com/chart/vKzVQllW/#")
browser.maximize_window()


# wait up to 10 seconds for page to load
timeout = 10
try:
    WebDriverWait(browser, timeout).until(EC.visibility_of_element_located((By.XPATH, "/html/body/div[1]")))
except TimeoutException:
    print("Timed out waiting for page to load")
    browser.quit()


time.sleep(5)

content = browser.find_element_by_xpath("/html/body/div[1]/div[1]/div/div[1]/div/table/tbody/tr[1]/td[2]/div/canvas[2]")
png = content.get_screenshot_as_file("screenshot.png")

我已经尝试过这个功能,.get_screenshot_as_png两个都给了我同样的错误

Traceback (most recent call last):
  File "C:/Users/logan/PycharmProjects/USDTtotheMoon/TEST.py", line 35, in <module>
    png = content.get_screenshot_as_file("screenshot.png")
AttributeError: 'WebElement' object has no attribute 'get_screenshot_as_file'

我希望用seleninum跟踪最新的蜡烛价格信息,但必须将鼠标悬停在脚本中的最新蜡烛上。悬停在最新蜡烛上的问题来了。我被告知需要截取画布的蜡烛的x y坐标。但现在我无法获取屏幕截图。

有关如何获取屏幕截图的任何建议?或者更具体地说是蜡烛的x y坐标

tradingview link

0 个答案:

没有答案