-1

Below is the source code which i am getting after browsing a website

<item><a href="/search/Listing/45678489?source=results" id="mk:0:mk" class="details">

I just want to copy link /search/Listing/45678489?source=results in excel and want to know how to click it

class="details" is same for all href links that i want copy while id keep on incrementing mk:1:mk, ms:2:mk and so on

JvdV
  • 70,606
  • 8
  • 39
  • 70
Jazz
  • 9
  • 2
  • so you want a single link or multiple? The id increments for different links or for the same link? When does it it increment? – QHarr Nov 10 '19 at 15:31
  • @QHarr, Multiple Links, id increments for every product listing. Basically i am trying to browse a website and then want to fetch details from each product listing on that browsed page(category page you can say) – Jazz Nov 10 '19 at 15:42
  • Can you share the link? And are you using IE? – QHarr Nov 10 '19 at 21:22
  • @QHarr, yes using IE, would not be able to share the link – Jazz Nov 11 '19 at 04:07

1 Answers1

0

So, on each page you can gather the current set of links in a list but looking at your above example you will need to concatenate on the protocol/domain to the url before writing out to Excel. I wouldn't try clicking those written out links (hyperlinks presumably) as this is inefficient and will spawn lots of IE instances you will need to remember to manually close.

On any given page grab the list of links and generate a full url in each case

Dim nodes As Object, i As Long

Set nodes = ie.document.querySelectorAll(".details[id^='mk:']")

With ActiveSheet
    For i = 0 To nodes.Length -1
        .Cells(i+1,1) = "protocol + domain...." & nodes.item(i).href
    Next
End With

Then later, rather than clicking, read those urls into an array, loop the array and either issue xmlhttp requests if possible, or .Navigate with IE to the current url in the array.

QHarr
  • 83,427
  • 12
  • 54
  • 101