How to webscrape from Marketwatch Financials for Google Sheets

Viewed 32

I want to scrape data from MarketWatch. I have a formula to pull from Finviz:

=value(regexextract(query(importhtml("http://finviz.com/quote.ashx?t="&$C7,"table",9),"select Col2 where Col1 = 'Income' ",0),"[-\d.]+"))

Note: The C7 box contains SBSW.

How do I scrape the Sales/Revenue of 2021 for the ticker SBSW. Here's the link: https://www.marketwatch.com/investing/stock/SBSW/financials

The result should show 172.19

1 Answers

I tested using this formula, and it works for me:

=IMPORTXML("https://www.marketwatch.com/investing/stock/SBSW/financials", "//*[@id='maincontent']/div[6]/div/div[2]/div/div/table/tbody/tr[1]/td[6]/div/span")

And it looks like this:

enter image description here

You can get the xpath_query with the developer tools like this:

enter image description here

Edit answer, removing the B at the end

First option

If the letter is always "B."

=SUBSTITUTE(IMPORTXML("https://www.marketwatch.com/investing/stock/SBSW/financials", "//*[@id='maincontent']/div[6]/div/div[2]/div/div/table/tbody/tr[1]/td[6]/div/span"),"B","")

Second option

If the letter at the end always changes.

=REGEXEXTRACT(IMPORTXML("https://www.marketwatch.com/investing/stock/SBSW/financials", "//*[@id='maincontent']/div[6]/div/div[2]/div/div/table/tbody/tr[1]/td[6]/div/span"),"[0-9]+.+[0-9]")

Reference:

Related