Jump to content

Find and extract from website.


Recommended Posts

Hello all,

I'm fairly new with using AutoIt, I've only written scripts for pranks and novelty. But now I seem to have a real need for it:

My problem

There is this website that sells electronic components, I want to be able to extract a few pieces of information from the listings and load them into an Excel spreadsheet for analyzation.

An example

http://www.newark.com/jsp/search/results.j...AN_PART_NUM%7c0

I would need to extract the price, capacitance and voltage from each on that page.

Then that info would need to be placed into Excel.

Is this at all feasible, and if so, does anyone have any suggestions of how or where to start?

Thanks,

Doug

Link to comment
Share on other sites

Is this at all feasible, and if so, does anyone have any suggestions of how or where to start?

Of course :) take a look in the helpfile at all of the _IE functions.

A list of functions that would be useful:

  • _IETableGetCollection
  • _IETableWriteToArray
  • StringRegExpReplace/StringReplace
  • StringSpilt could be useful :)
Link to comment
Share on other sites

  • Moderators

Quick and dirt, but it works!

#include <IE.au3>
#include <GUIConstants.au3>
#Include <GuiListView.au3>

Opt("GuiOnEventMode", True)

$GUI = GUICreate("Newark", 620, 370)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
$ListView1 = GUICtrlCreateListView("Newark Part #|Name & Part #|Description|RoHS|Avail.|" & _
        "Price For|List Price|Capacitance|Tolerance|Voltage|Terminal Type|Series", 10, 10, 600, 350)
GUISetState(@SW_SHOW)

_SearchNewark()

While 1
    Sleep(10)
WEnd

Func _SearchNewark()
    _GUICtrlListViewDeleteAllItems($ListView1)
    Ping("www.newark.com")
    If @error Then
        MsgBox(0, "Connection Error!", "There was a problem connecting to the internet.")
        Return
    EndIf

    $oIE = _IECreate("http://www.newark.com/jsp/search/results.jsp?N=1000121&Ns=PLS_NIC_FLAG%7c0%7c%7cPLS_MAN_PART_NUM%7c0", 0, 0)
    $oTable = _IEGetObjByName($oIE, "searchResults")
    $aResults = _IETableWriteToArray($oTable)
    _IEQuit($oIE)

    For $i = 2 To UBound($aResults, 2) - 1
        $sPN = $aResults[1][$i]
        $sNamePN = $aResults[2][$i]
        $sDesc = $aResults[3][$i]
        $sRoHS = $aResults[5][$i]
        $sAvail = $aResults[6][$i]
        $sPriceFor = $aResults[8][$i]
        $sListPrice = $aResults[9][$i]
        $sCapacitance = $aResults[11][$i]
        $sTolerance = $aResults[12][$i]
        $sVoltage = $aResults[13][$i]
        $sType = $aResults[14][$i]
        $sSeries = $aResults[15][$i]

        If $aResults[0][$i] == 0 Then ContinueLoop
        $lv_item = GUICtrlCreateListViewItem($sPN & "|" & $sNamePN & "|" & $sDesc & "|" & $sRoHS & "|" & _
                $sAvail & "|" & $sPriceFor & "|" & $sListPrice & "|" & $sCapacitance & "|" & _
                $sTolerance & "|" & $sVoltage & "|" & $sType & "|" & $sSeries, $ListView1)
    Next
    For $i = 0 To 6
        _GUICtrlListViewSetColumnWidth($ListView1, $i, $LVSCW_AUTOSIZE)
    Next
EndFunc   ;==>_SearchNewark

Func _Exit()
    Exit
EndFunc   ;==>_Exit
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...