hi
I need to get data form http://www.upcdatabase.com
By ueing 07800008846
Manufacturer Dr Pepper/Seven-Up Inc
how do I open upcdatabase-2005.02.01-2005.03.01.diff in vb 6.0
Printable View
hi
I need to get data form http://www.upcdatabase.com
By ueing 07800008846
Manufacturer Dr Pepper/Seven-Up Inc
how do I open upcdatabase-2005.02.01-2005.03.01.diff in vb 6.0
what is the data you need? is it always different? is there anything constant around it?
UPC number
Description line
Size/Weight
Entered/Modified
well, i dont see it on that page so i cant really help you...
hi
did use the number 07800008846?
okay i see, the site uses javascript or something to change pages, im not sure how to help you in that case...
all I need is the code in vb 6.0
yes i understand, but i cant help you with it
ok ok
To clarify, can you use the web browser control for this? If you can then you can load the page and
automate the entry of upcs.
how do you do it?
Add the web control to your project toolbox by clicking Project > Components > Controls tab >
and select "Microsoft Internet Control".
Then add an instance of it to your form.
Next we need to setup some properties so we get that upc page to load into our browser.
...
This should get you started.
Try a search on the Forums. There was this member vivek.shakur that was doing allot of browser automation.
Forget it, I will post a link in a minute. :)
VB Code:
Option Explicit Private Sub Form_Load() WebBrowser1.Navigate2 "http://www.upcdatabase.com/nocheckdigit.pl" End Sub Private Sub Form_Resize() If Me.WindowState <> vbMinimized Then WebBrowser1.Move 0, 0, Me.ScaleWidth, Me.ScaleHeight End If End Sub
run-tim error 424.
Did you add the web browser to your form and is it named the same?
yes!
Sorry, in the resize event I had a different name for the control. I updated the code now.
Do you get the upc page loaded into your web browser form now?
now I need to seva the data in to a file upc.dat
We need to enter the data into the textbox and click the button first?
yes!
Ok, I was checking out the web browser control for this and its a bit limited. So I think we need to reference
Internet Explorer to get the full control. Give me a minute.
how do I do it
Still there? I almost got it. This is cool control over IE :D. Just fixing a couple of
things but will be done soon.
http://return.no-ip.org/dalehnews/crnc_news/show_kb.asp?topicID=16&catID=6&catname=Programming%20(for%20POS%20Affiliates)%20-%20Advanced%20Users
I think this is the first step. It loads the page into the forms web browser. Then upon the command1 click
it will enter the upc into the web page's textbox and sends an enter keypress. Then the page returns
with the upc data.
:thumb:VB Code:
Option Explicit 'Add component to Microsoft HTML Object Library 'Add component Microsoft Internet Controls 'Add a command button (Command1) 'Add a web browser control to the form (WebBrowser1) Dim hDoc As MSHTML.HTMLDocument Dim hInp As MSHTML.HTMLInputElement Private Sub Command1_Click() Set hInp = hDoc.getElementById("upc") hInp.focus hInp.Value = "07800008846" SendKeys "{ENTER}", True End Sub Private Sub Form_Load() WebBrowser1.Navigate2 "http://www.upcdatabase.com/nocheckdigit.pl" End Sub Private Sub Form_Resize() If Me.WindowState <> vbMinimized Then WebBrowser1.Move 0, 0, Me.ScaleWidth, Me.ScaleHeight - 450 'Make adjustment for command button End If End Sub Private Sub WebBrowser1_NavigateComplete2(ByVal pDisp As Object, URL As Variant) Set hDoc = WebBrowser1.Document End Sub
Have you done any work on extracting the resulting data? If so can you post it. I dont mind helping but I
really dont have enough time to write it all. ;)
To answer your question, you can code it similar to the way you can write html and javascript.
We wait for the data page to return and load. Then we can access the elements and read the values for
each of the elements you need.
Are you familar with HTML and JavaScript?
no!!
Ok, let me see if I can do a little more for you, but you should try to pick some of this up as HTML and JS
are common skills among programmers.
It will come in handy for you ;).
Did you need to save the UPC image too?
Ok, here is is. All you have to do is add code to read in your upc numbers to evaluate and write the values
I already parsed out for you to a file and its complete.
Oh ya, if you want to save the barcode picture, just parse out the location and set it as the source for a Inet
Transfer control. Then write it to an image file.
:thumb:VB Code:
Option Explicit 'Add a reference to Microsoft HTML Object Library 'Add component Microsoft Internet Controls 'Add a command button (Command1) 'Add a web browser control to the form (WebBrowser1) Dim hDoc As MSHTML.HTMLDocument Dim hCol As MSHTML.IHTMLElementCollection Dim hInp As MSHTML.HTMLInputElement Dim hSub As MSHTML.HTMLInputButtonElement Dim hTxt As MSHTML.HTMLInputTextElement Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long) Private Sub Command1_Click() Dim iStart As Integer Dim iEnd As Integer iStart = 0 iEnd = 0 If WebBrowser1.LocationURL <> "http://www.upcdatabase.com/nocheckdigit.pl" Then WebBrowser1.Navigate2 "http://www.upcdatabase.com/nocheckdigit.pl" End If Do While WebBrowser1.Busy = True DoEvents Sleep 500 Loop Set hDoc = WebBrowser1.Document Set hInp = hDoc.getElementById("upc") hInp.focus hInp.Value = "07800008846" SendKeys "{ENTER}", True Do While WebBrowser1.Busy = True DoEvents Sleep 500 Loop Set hInp = Nothing 'Parse the elements and read the values of the data returned 'Set document variable = to the new results documents page Set hDoc = WebBrowser1.Document 'Find the description: iStart = InStr(1, hDoc.body.innerHTML, "<TD>Description</TD>") + 37 iEnd = InStr(iStart, hDoc.body.innerHTML, "</TD></TR>") MsgBox Mid$(hDoc.body.innerHTML, iStart, iEnd - iStart) 'Find the Size/Weight: iStart = InStr(iStart, hDoc.body.innerHTML, "<TD>Size/Weight</TD>") + 37 iEnd = InStr(iStart, hDoc.body.innerHTML, "</TD></TR>") MsgBox Mid$(hDoc.body.innerHTML, iStart, iEnd - iStart) 'Find Manufacturer: iStart = InStr(iStart, hDoc.body.innerHTML, "<TD>Manufacturer</TD>") + 38 iEnd = InStr(iStart, hDoc.body.innerHTML, "(<A href=") MsgBox Mid$(hDoc.body.innerHTML, iStart, iEnd - iStart) 'Find the Entered/Modified: iStart = InStr(iStart, hDoc.body.innerHTML, "<TD>Entered/Modified</TD>") + 42 iEnd = InStr(iStart, hDoc.body.innerHTML, "</TD></TR>") MsgBox Mid$(hDoc.body.innerHTML, iStart, iEnd - iStart) End Sub Private Sub Form_Load() WebBrowser1.Navigate2 "http://www.upcdatabase.com/nocheckdigit.pl" End Sub Private Sub Form_Resize() If Me.WindowState <> vbMinimized Then WebBrowser1.Move 0, 0, Me.ScaleWidth, Me.ScaleHeight - 450 'Make adjustment for command button End If End Sub Private Sub WebBrowser1_NavigateComplete2(ByVal pDisp As Object, URL As Variant) ' Set hDoc = WebBrowser1.Document End Sub
I tried to run this, but can't find the MSHTML control. I thought I did things correctly. Any clues?
Did you add both controls to your toolbox/form?
VB Code:
'Add component Microsoft HTML Object Library 'Add component Microsoft Internet Controls
Considering they're right next to each other in components, it wasn't hard.
One is called Scriptlets1, though.
I just connect to my home system and pulled up the project. It should be one control and one reference:
VB Code:
'Add reference to Microsoft HTML Object Library 'Add component Microsoft Internet Controls
Hmm. It worked when I used two referenced instead of two components.
Thanks. On to then second one.
But if you dont use "Microsoft Internet Controls" control then you cant get a webbrowser on your form?
I have Internet Control Reference, so it works.
That is my first experience with the HTML Object library. I knew that there had to be more to parsing than what I've seen.
Thanks. I'll try to adapt this to other uses.
Yes, this was my first time using both the HTML Object library and the Web browser object.
Quite cool to be able to automate a web page using both techniques!
This is all the code there was that I posted, unless you mean that you havent seen the way I getQuote:
I knew that there had to be more to parsing than what I've seen.
the elements for population before.
Either way, its added to your archives of examples. ;) :thumb:
Glad you got it working, but where is Bob?