试图从 dividendinvestor.com 中抓取数据
Trying to scrape data off of dividendinvestor.com
我正在尝试使用 Google 表格导入一些关于股息历史的股票数据。
我要抓取的数据来自这个页面:https://www.dividendinvestor.com/dividend-quote/
(例如 https://www.dividendinvestor.com/dividend-quote/ibm or https://www.dividendinvestor.com/dividend-quote/msft)
对于其他站点,我已经能够结合使用 INDEX 和 IMPORTHTML 从 table 获取数据。例如,如果我想从 finviz.com 获取 IBM 的“Forward P/E
”,我会这样做:
=index(IMPORTHTML("http://finviz.com/quote.ashx?t=IBM","table", 11),11,10)
抓取 table 11 并向下移动 11 行和 10 多列以获得我想要的数据。
但是,我似乎找不到任何 table 可以从 www.dividendinvestor.com/dividend-quote/ibm 站点通过 IMPORTHTML 导入。
我正在尝试导入“连续股息增加”字段右侧的值。
在这种情况下,我要实现的输出是“19 年”。
我也试过 IMPORTXML,但是我用 XPATH (using this path: "/html/body/div[3]/div/div/div[2]/div/div/div[2]/div[2]/div[2]/span[20]" )
尝试的一切都失败了。
有什么帮助吗?期望的最终结果将是我将通过附加不同的股票代码动态构建 dividendinvestor.com URL,并得到其股息支付连续增加多少年的结果。
尝试:
=INDEX(IMPORTXML("https://www.dividendinvestor.com/dividend-quote/ibm/",
"//span[@class = 'data']"), 9, 1)
@player0 提出的不错的解决方案。如果你不想使用 INDEX
,你可以使用 :
=IMPORTXML("https://www.dividendinvestor.com/dividend-quote/"&B3,"//a[.='Consecutive Dividend Increases']/following::span[1]")
更新(2022 年 5 月):
新的工作公式:
=REGEXEXTRACT(TEXTJOIN("|";TRUE;IMPORTXML("https://www.dividendinvestor.com/ajax/?action=quote_ajax&symbol="&B2;"//text()"));"\d+ Years")
注意:我在欧洲,所以分号可能需要用逗号代替。
我正在尝试使用 Google 表格导入一些关于股息历史的股票数据。
我要抓取的数据来自这个页面:https://www.dividendinvestor.com/dividend-quote/
(例如 https://www.dividendinvestor.com/dividend-quote/ibm or https://www.dividendinvestor.com/dividend-quote/msft)
对于其他站点,我已经能够结合使用 INDEX 和 IMPORTHTML 从 table 获取数据。例如,如果我想从 finviz.com 获取 IBM 的“Forward P/E
”,我会这样做:
=index(IMPORTHTML("http://finviz.com/quote.ashx?t=IBM","table", 11),11,10)
抓取 table 11 并向下移动 11 行和 10 多列以获得我想要的数据。
但是,我似乎找不到任何 table 可以从 www.dividendinvestor.com/dividend-quote/ibm 站点通过 IMPORTHTML 导入。
我正在尝试导入“连续股息增加”字段右侧的值。
在这种情况下,我要实现的输出是“19 年”。
我也试过 IMPORTXML,但是我用 XPATH (using this path: "/html/body/div[3]/div/div/div[2]/div/div/div[2]/div[2]/div[2]/span[20]" )
尝试的一切都失败了。
有什么帮助吗?期望的最终结果将是我将通过附加不同的股票代码动态构建 dividendinvestor.com URL,并得到其股息支付连续增加多少年的结果。
尝试:
=INDEX(IMPORTXML("https://www.dividendinvestor.com/dividend-quote/ibm/",
"//span[@class = 'data']"), 9, 1)
@player0 提出的不错的解决方案。如果你不想使用 INDEX
,你可以使用 :
=IMPORTXML("https://www.dividendinvestor.com/dividend-quote/"&B3,"//a[.='Consecutive Dividend Increases']/following::span[1]")
更新(2022 年 5 月):
新的工作公式:
=REGEXEXTRACT(TEXTJOIN("|";TRUE;IMPORTXML("https://www.dividendinvestor.com/ajax/?action=quote_ajax&symbol="&B2;"//text()"));"\d+ Years")
注意:我在欧洲,所以分号可能需要用逗号代替。