Asked by:
How to extract link href value using vba

Question
-
I want to extract href link value from a webpage using access vba.Html code is given below.I want to extract following value
/s/ref=sr_in_-2_p_6_0?fst=as%3Aoff&rh=n%3A318949011%2Cp_6%3AA3P5ROKL5A1OLE%7CA1HZ5FPD8FVC3N&
Sample HTML is given below.
</span></div></div></div></div><div class="a-row a-spacing-base"><div class="a-column a-span12 a-text-center"></div></div><div class="a-row a-spacing-medium"><div id="refinementList" class="a-row a-spacing-none"><div id="ref_401720011" class="a-row a-spacing-none s-see-all-c3-refinement s-see-all-refinement-list"><ul class="s-see-all-indexbar-column">
<li><span class="a-list-item"><a class="a-link-normal" title="Adventure Northumberland" href="/s/ref=sr_in_-2_p_6_0?fst=as%3Aoff&rh=n%3A318949011%2Cp_6%3AA3P5ROKL5A1OLE%7CA1HZ5FPD8FVC3N&bbn=318949011&ie=UTF8&qid=1455259722&rnid=401720011"><span class="refinementLink">Adventure Northumberland</span><span class="narrowValue"> (22,585)</span></a></span><Thanks
- Edited by tahirsatti123 Sunday, February 14, 2016 1:39 AM
Friday, February 12, 2016 5:46 PM
All replies
-
Dim strV As String
Dim i As Long
Dim j As Long
strV = "Long string you posted"
i = InStr(1, strV, "href=")
j = InStr(1, strV, ";bbn=")
MsgBox Mid(strV, i + 6, j - i - 6)- Marked as answer by tahirsatti123 Thursday, February 18, 2016 12:01 PM
- Unmarked as answer by tahirsatti123 Thursday, February 18, 2016 12:11 PM
Wednesday, February 17, 2016 7:54 PM -
thanks for your response,actually i want to extract href value from from following Webpage
http://www.amazon.co.uk/gp/offer-listing/B00IKFN8YM/ref=olp_page_2?ie=UTF8&f_new=true
HTML is in this format
<div class="a-column a-span3 olpDeliveryColumn"> <p class="a-spacing-mini olpAvailability"> <ul class="a-vertical"> <li class="olpFastTrack"><span class="a-list-item"> In stock. </span></li> <li><span class="a-list-item"> Dispatched from Hong Kong. <a href="/gp/help/customer/display.html/ref=olp_intl_help?ie=UTF8&nodeId=502492">Learn more</a> about international shipping. </span></li> <li><span class="a-list-item"> Expedited delivery available. </span></li> <li><span class="a-list-item"> <a href="/gp/aag/details/ref=olp_merch_ship_1?ie=UTF8&asin=B00IKFN8YM&seller=ABF4V1ARUVKO9&sshmPath=shipping-rates#aag_shipping">International & domestic delivery rates</a> and <a href="/gp/aag/details/ref=olp_merch_return_1?ie=UTF8&asin=B00IKFN8YM&seller=ABF4V1ARUVKO9&sshmPath=returns#aag_returns">return policy</a>. </span></li> </ul> </p> </div>
I want to extract only below mentioned href value.
a href="/gp/aag/details/ref=olp_merch_ship_1?ie=UTF8&asin=B00IKFN8YM&seller=ABF4V1ARUVKO9&sshmPath=shipping-rates#aag_shipping"
Thanks.
Thursday, February 18, 2016 12:08 PM -
If I was doing this I would use regular expressions. Here is some info on it. The regular expression will look like this:
href="(.*)">International & domestic delivery rates
If I have time later I may add more detail.
Thursday, February 18, 2016 3:40 PM -
Sir..i am using IE navigation for extraction.Is this possible that i will use code just like below mentioned.
IE.navigate "http://www.amazon.co.uk/gp/offer-listing/B00IKFN8YM/ref=olp_page_2?ie=UTF8&f_new=true" Do While IE.ReadyState <> 4 Or _ IE.Busy = True On Error Resume Next ' MsgBox (ie.ReadyState) DoEvents Loop 'Set html = CreateObject("htmlfile") Set html = IE.Document Set priceData2 = html.getElementsByClassName("a-column a-span3 olpDeliveryColumn").getElementsByTagName("a") For Each Item In priceData2 Debug.Print Item.innerHTML Priceval2 = Item.innerHTML MsgBox (Priceval2) Next Item
Please modify above code to have href value..thanksThursday, February 18, 2016 4:02 PM