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:
You can get the xpath_query with the developer tools like this:
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: