Jump to content

Need Help Pulling information from a web page.


Recommended Posts

I am creating a script that will take the input from a barcode scanner and open a webpage to http://www.upcindex.com and search for the barcode. I have it working up until the point that i need to pull the name of the product. There is the link to the product page. http://www.upcindex.com/810354020292. and here is my code so far:

;Includes=======================================================================================================================================

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <StaticConstants.au3>
#include <ListViewConstants.au3>
#include <Array.au3>
#include <MsgBoxConstants.au3>
#include <GuiListView.au3>
#include <IE.au3>
#RequireAdmin

;Variables=======================================================================================================================================

;Gui=============================================================================================================================================

;MainGUI=====
$Barcode = InputBox("Barcode", "Please Scan Barcode", Default, Default, 200, 120, 20, 40)
$sUrl = "http://www.upcindex.com/search?q=" & $Barcode
$oIE = _IECreate($sUrl, 0, 1, 0, 1)
Sleep(2000)
$oHWND = _IEPropertyGet($oIE, "hwnd")
WinSetState($oHWND, "", @SW_MAXIMIZE)

;Loop============================================================================================================================================

Local $GUIMsg
While 1
    Switch GUIGetMsg()
       Case $GUI_EVENT_CLOSE
          Exit
    EndSwitch
WEnd

I'm having issues try to figure out what function i need to use to pull the product name from the page. Anyone have any suggestions?

Link to comment
Share on other sites

You can read the HTML source and get the product name by searching the text between <strong> and </strong>. For that, you can use _IEBodyReadHTML.

In my code, I use StringRegExp, but you can do the same thing with some other string functions (_StringBetween, StringMid...)

#Include <IE.au3>

$Barcode = "810354020292"

; One way -------------------
$sHTML = BinaryToString( InetRead("http://www.upcindex.com/" & $Barcode) )
; ---------------------------

; IE way --------------------
$oIE = _IECreate("http://www.upcindex.com/" & $Barcode)
$sHTML = _IEBodyReadHTML($oIE)
; ---------------------------

$aProduct = StringRegExp($sHTML, '<strong itemprop="name">(.+?)</strong>', 1)
If IsArray($aProduct) Then
    MsgBox(0, "", "Product name for " & $Barcode & " is :" & @CRLF & $aProduct[0])
Else
    MsgBox(16, "", "No product found for " & $Barcode)
EndIf

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...