从iq选项中提取数据

时间:2019-07-18 07:12:36

标签: python selenium

我需要从iq选项中提取信息,但发现画布难以访问

我正在将python与selenium一起使用,到目前为止,我已经能够使用用户名和密码登录:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
import json
import time

class ClassBotIqOption():
    def __init__(self):

        self.CHROMEDRIVER_PATH = '/usr/bin/chromium-browser'
        self.URL = "https://iqoption.com/traderoom/"
        self.URL2 = "https://iqoption.com/en/login"


    def start_driver(self):
        options = Options()

        options.binary_location = self.CHROMEDRIVER_PATH
        options.add_argument('--headless')
        options.add_argument('--no-sandbox')
        options.add_argument('--disable-dev-shm-usage')
        options.add_argument('--ignore-certificate-errors')
        options.add_argument("--test-type")
        #self.chromeBrowser = webdriver.Chrome(executable_path = self.CHROMEDRIVER_PATH, chrome_options = options)
        self.chromeBrowser = webdriver.Chrome(chrome_options = options)


    def status_page(self, element_located, url):
        self.start_driver()
        self.chromeBrowser.get(url)
      Exception
        try:
            wait = WebDriverWait(self.chromeBrowser,5)
            element = wait.until(EC.presence_of_element_located((By.XPATH, element_located)))
        except TimeoutException:
            return False
        return True


    def close_driver(self):
        self.chromeBrowser.close()
        self.chromeBrowser.quit()

    def login(self, email, pw):
        self.chromeBrowser.get(self.URL2)
        time.sleep(10)
        txtemail = self.chromeBrowser.find_element_by_xpath('//input[@name="email"]')
        txtemail.send_keys(email)
        txtpw = self.chromeBrowser.find_element_by_xpath('//input[@name="password"]')  
        txtpw.send_keys(pw)
        submit_button = self.chromeBrowser.find_element_by_xpath('//button[@data-test-id="login-submit-button"]')        
        submit_button.click()
        time.sleep(10)
        element = self.chromeBrowser.find_elements_by_id('traderoom')
        if (len (element)>0):
            print("success...")
        else:
            print("login failure")

#    def logout(self):



BotIqOption = ClassBotIqOption()
BotIqOption.start_driver()
status = BotIqOption.status_page('//*[@class="topleft"]', "https://iqoption.com/traderoom/")
if (status == True):
    print("exit...")
else:
    print("error...")
BotIqOption.login("xxx@gmail.com", "xxxxx")
BotIqOption.get_data()
BotIqOption.close_driver()

我希望从资产负债表中获取信息。

这是我无法抓取的画布标识元素: id=glcanvas

有什么想法请刮一下该元素吗?

0 个答案:

没有答案