0

I have a trouble with getting URL from the website: https://searchbzp.uzp.gov.pl/Search.aspx
On this website there is a table.
The text 'Zobacz' is a hyperlink and from this place I want to get URL.

I can click on this url using below code, and then browser trying to open new tab: IE.Document.getelementbyID("ctl00_ContentPlaceHolder1_ASPxGridView1_DXCBtn0").Click

But I want to get this URL only (without opening new tab). I was trying to something like this, but it doesn’t work:

Dim a
a = IE.Document.parentWindow.ExecScript("javascript:ctl00_ContentPlaceHolder1_ASPxGridView1_DXCBtn0", "JavaScript")
MsgBox a
a = IE.Document.parentWindow.ExecScript(IE.Document.getElementById("ctl00_ContentPlaceHolder1_ASPxGridView1_DXCBtn0").href, "JavaScript")
MsgBox a

Can anybody help me with it?

Bradmage
  • 1,233
  • 1
  • 15
  • 41

1 Answers1

0

See my answer to a similar question yesterday: http://stackoverflow.com/a/47593832/8112776

If you just need to get one value, that is always located in the same place, then there's no need for IE objects and all that.


Here:

Function GetHTML(url As String) As String
    With CreateObject("MSXML2.XMLHTTP")
        .Open "GET", url, False
        .Send
        GetHTML = .ResponseText
    End With
End Function


Sub getData()
    Const url = "https://searchbzp.uzp.gov.pl/Search.aspx"
    Const strStart = "ctl00_ContentPlaceHolder1_ASPxGridView1_DXCBtn0""><span>"
    Const strStop = "</span>"

    Dim html As String, pStart As Long, pStop As Long
    html = GetHTML(url)
    pStart = InStr(1, html, strStart) + Len(strStart)
    pStop = InStr(pStart, html, strStop)
    MsgBox Mid(html, pStart, pStop - pStart)
End Sub
ashleedawg
  • 20,365
  • 9
  • 72
  • 105
  • Thx ashleedawg, but if I use your code I get Value „Zobacz” not direct hyperlink. Part of html: < a class="dxbButton_Aqua dxgvCommandColumnItem_Aqua dxgv__cci dxbButtonSys" data-args="[['CustomButton','btnShow',0],1]" id="ctl00_ContentPlaceHolder1_ASPxGridView1_DXCBtn0" href="javascript:;" > < span>Zobacz< /span> < /a> When I use code: IE.Document.getelementbyID("ctl00_ContentPlaceHolder1_ASPxGridView1_DXCBtn0").Click Browser open website: https://bzp.uzp.gov.pl/ZP403/Preview/848ff3f8-1869-4157-b726-0b6e191fd1d3 The question is how to get this Value as URL? – MuzaMeduza Dec 04 '17 at 07:18
  • ok, I'm sorry I misunderstood the question. That link does not contain a URL, it runs a JavaScript function, and as far as I can tell, the site is intentionally trying to hide the link. The function opens page https://bzp.uzp.gov.pl/ZP403/Preview/581ee816-7a25-4a1a-ad3c-a910f497ef78 but that link doesn't appear anywhere in the source, so it's probably pieced together, and looks possibly partly random. With enough time somebody could probably figure out a way to extract the link but that's beyond my commitment to working for free. :-) Sorry about that, good luck! – ashleedawg Dec 04 '17 at 10:36
  • Ok. Thank you very much ashleedawg for your help!:) – MuzaMeduza Dec 04 '17 at 19:13