1
votes

I am scraping FINVIZ financial data using the google sheets IMPORTXML function, specifically:

=IMPORTXML("http://finviz.com/quote.ashx?t="&B1,"//table[@id='news-table']/tr")

Against the following source:

<table width="100%" cellpadding="1" cellspacing="0" border="0" id="news-table" class="fullview-news-outer">
    <tr>
        <td width="130" align="right" style="white-space:nowrap">Feb-15-20 03:58PM&nbsp;&nbsp;</td>
        <td align="left"><a href="https://finance.yahoo.com/news/u-evacuate-citizens-quarantined-ship-043646253.html" target="_blank" class="tab-link-news">U.S. Woman From Cruise Falls Ill as 2,200 Head Home: Virus Update</a> <span style="color:#aa6dc0;font-size:9px">Bloomberg</span></td>
    </tr>
    <tr>
        <td width="130" align="right">03:41PM&nbsp;&nbsp;</td>
        <td align="left"><a href="https://www.marketwatch.com/story/afraid-of-sky-high-stock-valuations-consider-this-deep-value-strategy-2020-02-12?siteid=yhoof2&yptr=yahoo" target="_blank" class="tab-link-news">Afraid of sky-high stock valuations? Consider this deep value strategy</a> <span style="color:#aa6dc0;font-size:9px">MarketWatch</span></td>
    </tr>
    <tr>
        <td width="130" align="right">10:47AM&nbsp;&nbsp;</td>
        <td align="left"><a href="https://www.marketwatch.com/story/if-you-could-buy-only-one-stock-for-5g-and-artificial-intelligence-this-would-be-it-2020-02-14?siteid=yhoof2&yptr=yahoo" target="_blank" class="tab-link-news">If you could buy only one stock for 5G and artificial intelligence, this would be it</a> <span style="color:#aa6dc0;font-size:9px">MarketWatch</span></td>
    </tr>
</table>

Hence, if I choose the stock ticker for Apple (AAPL) then the XPATH component of the IMPORTXML call above returns the following:

enter image description here

Question: How do I modify the XPATH component to make the news description clickable to its HREF?

I DO NOT want the URL to replace the news - just the news to point to its destination such that clicking the news takes me to the link.

1
Awesome dude! Thanks so much for your quick feedback! - waltz777
One other question: The date format for row 2 in your screenshot below shows 15:41:00. Mine, shows 1899-12-30 03:41:00pm. How do I get it to show time only when the integer value of the date < 1 like you did ? - waltz777

1 Answers

0
votes

try:

=ARRAYFORMULA({INDEX(IMPORTXML("http://finviz.com/quote.ashx?t="&B1,
 "//table[@id='news-table']/tr"),,1), 
 HYPERLINK(IMPORTXML("http://finviz.com/quote.ashx?t="&B1,
 "//table[@id='news-table']/tr//a/@href"), 
 INDEX(IMPORTXML("http://finviz.com/quote.ashx?t="&B1,
 "//table[@id='news-table']/tr"),,2))})

0