Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB6 pass a search string to the website and get the result string(s)? 2

Status
Not open for further replies.

mingichu

MIS
Apr 12, 2002
29
0
0
US

Hi! All experts,

I'm looking for a way to pass a search string to the website using VB and get the result string(s) back using VB6.

So far I only know to use WebBrowser control to "manually" do searching and get the result back as the same I do in the Internet Explore 6.
Q1: How to do that automatically using VB6?

I may use Inet control to download the HTML source codes of the result web page, read line by line using Scripting.TextStream and find the result string.
Q2: Is there a better way to do it?

By the way, my target searching websites are not Google, Yahoo kind of searching website.

Any help would be greatly appreciated!!!

 
Using the webbrowser control, you can use GetElementsByName to call specific objects. You need to know the name of the textbox on the page however. Therefore, you need to read the html for the page, and find the name of the textbox. Then, use:

Dim ObjText as Object

with WebBrowser
.Navigate " & myWebAddress
with .Document
Set ObjText = .GetElementsByName("TextBox1")
ObjText.Item.Value = "Some Text in the box"
set objText = nothing
end with
end with

To submit the text, you either need to post the page to the server, or declare another variable as on Object, and then set this to be the Submit button.

The webbrowser must be set to visible, although, you can hide it behind a label, or picturebox for this to work.

If you can post the web address, I may be able to give you a working sample of the code.

BB
 
You can also use the Internet control element
for example to querey google

Code:
dim page as string

 page = URL1.GetURL("[URL unfurl="true"]http://www.google.co.uk/search?q="[/URL] + search_string + "&ie=ISO-8859-1&hl=en&meta=")

Scan_4_Links(page)

Some search engions (like Google I think) won't alow you to querey them this way and block the content.
I haven't tryed it but.

Code:
 page = URL1.GetURL("[URL unfurl="true"]http://www.google.co.uk/")[/URL]

before the querey may help, or you could use BiggerBrother's neater way

Also if google changes there display page you'le have to change Scan_4_Links function.


-----
 
The only problem with Kirogl's solution is that it only works with websites that pass variables between pages within the address. If the page is ASP, CGI or similar, where the variables are passed within session variables, then this method won't work.

BB
 
I just tried to use VB6 with WebBrowser. I have a problem to call the search button on this website
The "Search the Database" button doesn't have NAME attribute in the HTML source codes. I put "",
frmWB.wb.Document.All("").Click
It didn't work. Please advice!

Below are the vb codes -
===================================
frmWB.wb.Navigate2 _
" frmWB.wb.Document.All("p_entity_name") = vSearchStr
'drop down list
frmWB.wb.Document.All("p_name_type").Value = "A"

'radio button
For Each btnRadio In frmWB.wb.Document.All.tags("INPUT")
If UCase$(btnRadio.Type) = "RADIO" _
And btnRadio.Name = "p_search_type" _
And btnRadio.Value = "CONTAINS" Then
btnRadio.Checked = True
Exit For
End If
Next
DoEvents

'Problem - The "Search the Database" button doesn't have the NAME
frmWB.wb.Document.All("").Click '??
=================================


==== partial HTML source code from the website===========
<table>
<td align="left"><input type="button" value="Search the Database" onClick="check_entity()" ></td>
<td align="left"><input type="button" name="reset_inp" value="Reset" onClick="reset_inputs()"></td>
<td align="left"><input type="button" name="display_help" value="Help" onClick="dsp_help()"></td></table>
</table>
=================================
 
I tried the code below and it worked.
=================================
Call frmWB.wb.Document.parentWindow.execScript("check_entity()")
=================================
Is it the way to call javascript to vb?? (I'm not familiar with web language...)
 
That's the way I would have done it. Sorry I didn't get back to you. Well worked out though.

Does everything work now?

BB
 
Thanks of your feedback!
I still have another problem: VB6 runs much faster than the webbrowser refresh the screen. When it runs to the 2nd page to click the button and type the string, the webbrowser is still on the 1st page. Should I use Timer? Is there any WebBrowser property or event which can prevent this problem?

Also, when I recall the code procedure, sometimes the website has session time-out, so it doesn't go to the 1st page. How do you solve this kind of problem?

Thanks in advance!!

P.S. Please let me know if I have to open another question for it.

==Below is my code ===========
frmWB.wb.Navigate2 _
"frmWB.wb.Navigate2 _
"
For Each btnRadio In frmWB.wb.Document.All.tags("INPUT")
If UCase$(btnRadio.Type) = "RADIO" _
And btnRadio.Name = "optSearchOption" _
And btnRadio.Value = "1" Then '1 - Business Entity Name
btnRadio.Checked = True
Exit For
End If
Next
DoEvents

frmWB.wb.Document.All("txtSearchText").Value = lBusSrcName

frmWB.wb.Document.All("go").Click

=========================================
 
When I have sent data to the webbrowser, and it need to load a new page, I simply use a dowhile loop, where it waits for the webBrowser.status to be LOADED

frmWB.wb.Navigate2 _
"[red]Do Until frmWB.wb.READYSTATE = READYSTATE_COMPLETE
DoEvents
Loop
[/red]
frmWB.wb.Navigate2 _
"[red]Do Until frmWB.wb.READYSTATE = READYSTATE_COMPLETE
DoEvents
Loop
[/red]
For Each btnRadio In frmWB.wb.Document.All.tags("INPUT")
If UCase$(btnRadio.Type) = "RADIO" _
And btnRadio.Name = "optSearchOption" _
And btnRadio.Value = "1" Then '1 - Business Entity Name
btnRadio.Checked = True
Exit For
End If
Next
DoEvents

frmWB.wb.Document.All("txtSearchText").Value = lBusSrcName

frmWB.wb.Document.All("go").Click
[red]Do Until frmWB.wb.READYSTATE = READYSTATE_COMPLETE
DoEvents
Loop
[/red]

You need to make sure the WebBrowser.Visible=True, but if you don't want your user to see the control, make it as small as it will go, and then, cover it with a label etc.

Hope this helps

BB
 
BiggerBrother,

Thank so much for your help!!!! It works very well!!
After doing lots of searching and testing, I still have another question for another website which has partial HTML codes -
<FORM ACTION="/servlet/TerminalServlet" METHOD="POST">
<INPUT TYPE="hidden" NAME="request" VALUE="disconnect">
<INPUT TYPE="submit" VALUE="Sign-off of the Concord system">
</FORM>

I'm going to post another question and hope you can help me out again!
 
How can you submit a form if the SUBMIT button is defined like this:
Code:
<FORM METHOD="POST" ACTION="SomeASP.asp">
...
<P>[b]<INPUT TYPE=SUBMIT>[/b]<INPUT TYPE=RESET>
</FORM>

I noticed the code above... (for a go button?)
mingichu said:
frmWB.wb.Document.All("go").Click

And this statement...
BiggerBrother said:
To submit the text, you either need to post the page to the server, or declare another variable as on Object, and then set this to be the Submit button.

How would you do the later? (setting a new object to the sbmit button)

Have Fun, Be Young... Code BASIC
-Josh
cubee101.gif


PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
To submit the text, you either need to post the page to the server, or declare another variable as on Object, and then set this to be the Submit button.

The latter method only works if the site is setup with a button, named, with an event. This way, you can call the button, as an object, and fire the event attached to the button. You can do this with:

Code:
Set ObjSubmit = .GetElementsByName("Submit")
ObjSubmit.Item.Click

This will fire the events associated with the button named Submit. If there is over scripting fort he button, such as hover or mouse down, this can be fired by changing the item.click to whatever the event is.

If the form is posted, by clicking on the button, with no apparent name, then the action needs to be directed at the form:

Code:
Call frmWB.wb.Document.Forms(1).submit

Where the forms number or name is called, and then the action is to submit.

Hope this helps. Must get round to writing the FAQ some day soon.

BB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top