Reputation: 83
I'm trying to figure out a way to extract information from an HTML source using a Visual Basic based application I made in Visual Studio 2010. What I'd like to do is have the system load a webpage (based on an order number) in the background and search for a value that is assigned to an HTML tag and return that value. For example, in the href string below:
href="#" class="lnk11blue" onClick="parent.gotoPage('/oe/cllctrshp_.html?dlvyId=26130700&hdrId=7205902&lineId=21188936&ordLnTyp=FEL SVC LINE','dWnd')">26130700
I want the tool to return the 26130700, either after the "dlvyId=" or at the end of the href. The issue I have is the dlvyId changes with every order, as probably does the hdrId and lineId values, so is there a way to have my program read the value after "dlvyId=" after it locates this string? Or is there a way for the program to read the text after the greater than carat after locating the string?
I'll mess around and see what I can find out (and hopefully post code of some attempts), but any ideas/help in the meantime would be greatly appreciated.
Edit: Thanks to Steve, I've got the function to search a string. However, now I'm having trouble loading the page source. I tried this code below but it doesn't seems to work:
Dim objHttp as object
Dim strURL As String
Dim strText As String
objHttp = CreateObject("MSXML2.ServerXMLHTTP")
strURL = "http://companywebprd.tc.company.com/oe/cllctrord_.html?order_nbr=" &
RMA_Number.Text & "&customer_id=&po_nbr=&ord_date=&ord_cond=0&ord_kind=0&serial_nbr=&item_id=
&i_ord_type=&instance=&svcChk=1&custSiteUseId=0&custSiteUseCd=0"
objHttp.Open("GET", strURL, False)
objHttp.Send("")
strText = objHttp.responsetext
Advice? I'll keep searching around as well
Upvotes: 0
Views: 878
Reputation: 36
This should get you started down the right path...
Sub test()
Const mystring = "href='#' class='lnk11blue' onClick='parent.gotoPage('/oe/cllctrshp_.html?dlvyId=26130700&hdrId=7205902&lineId=21188936&ordLnTyp=FEL SVC LINE','dWnd')'>26130700'"
If InStr(1, mystring, "dlvyId=") <> 0 Then
For i = InStr(1, mystring, "dlvyId=") To Len(mystring)
If Mid(mystring, i, 1) = "&" Then
Exit For
End If
Next i
MsgBox Mid(mystring, InStr(1, mystring, "dlvyId="), (i - InStr(1, mystring, "dlvyId=")))
End If
End Sub
Upvotes: 1