【问题标题】:change chart attributes using selenium使用 selenium 更改图表属性
【发布时间】:2015-01-03 16:14:04
【问题描述】:

我正在检索以下网址的来源:http://www.google.com/finance?q=EPA:RNO 使用 urllib2。

问题是图表的默认设置会排除一些要放置在页面源中的数据。因此,我需要在检索源之前与页面进行交互。

使用默认设置,如果你看下面这条线

<span class=settings-link>Settings</span> 

你有

_chartConfigObject.defaultInterval = '86400';

我需要把它改成

_chartConfigObject.defaultInterval = '1800';

我可以使用 Selenium 做到这一点吗?是否有其他方法,即使用我的浏览器 cookie 中保存的默认设置在检索 url 源之前自动设置正确的时间间隔?

【问题讨论】:

    标签: javascript python python-2.7 selenium selenium-webdriver


    【解决方案1】:

    有一个相关的URL参数chddi控制使用的区间:

    https://www.google.com/finance?chdnp=1&chdd=1&chds=1&chdv=1&chvs=Linear&chdeh=0&chfdeh=0&chdet=1415318689290&chddm=5210&chddi=1800&chls=CandleStick&q=EPA:RNO&ntsp=0&ei=hgxcVIDZDIuMqQHDmYDoCg
    

    我是怎么得到这个网址的?我刚刚设置了所需的图表设置并单击了生成 URL 的“链接到此视图”按钮。

    您可以使用 selenium 来控制图表设置,例如:

    from selenium import webdriver
    from selenium.webdriver.support.select import Select
    
    
    url = 'http://www.google.com/finance?q=EPA:RNO'
    driver = webdriver.Firefox()
    driver.get(url)
    
    settings = driver.find_element_by_class_name('settings-link')
    settings.click()
    
    candlestick = driver.find_element_by_xpath('//input[@value="CandleStick"]')
    candlestick.click()
    
    select = Select(driver.find_element_by_name('defaultInterval'))
    select.select_by_value('1800')
    

    【讨论】:

      猜你喜欢
      • 2015-05-02
      • 1970-01-01
      • 1970-01-01
      • 2021-09-09
      • 2021-02-12
      • 2017-01-18
      • 1970-01-01
      • 1970-01-01
      • 2016-11-05
      相关资源
      最近更新 更多