Jump to content

Get HTML Table Cell


Recommended Posts

Hello there,

I'd like to get some data from this site, but I don't have the slightest idea how to get the data from a specific table cell.

What I'm trying to automate is load the site, then search using the postcode from an excel file, then get back the data found on the site to the excel file.

The site is: [link]http://www.petrolprices.com/search.html?search=heathrow[/link]

The problem is I don't know how to get the "Lowest price in this area:" fields.

Do you have any idea where I can find an answer?

Thanks in advance!

Link to comment
Share on other sites

Hello there,

I'd like to get some data from this site, but I don't have the slightest idea how to get the data from a specific table cell.

What I'm trying to automate is load the site, then search using the postcode from an excel file, then get back the data found on the site to the excel file.

The site is: [link]http://www.petrolprices.com/search.html?search=heathrow[/link]

The problem is I don't know how to get the "Lowest price in this area:" fields.

Do you have any idea where I can find an answer?

Thanks in advance!

Look at User Defined Functions >> "IE Management " in the help file

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Look at User Defined Functions >> "IE Management " in the help file

Thank you, it seems that I can take out the data in to an array as it is a table. Unfortunately, I'll have to study working with arrays...I haven't done that before so it will be a long run.

Thanks again!

Link to comment
Share on other sites

Thank you, it seems that I can take out the data in to an array as it is a table. Unfortunately, I'll have to study working with arrays...I haven't done that before so it will be a long run.

Thanks again!

It's a good time to learn.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

  • Moderators

I'm really trying to find out how to get a specific cell from an array, but just can't figure it out.

Can you give me an example?

If you know the index number then it would look something like $array[$index_number].

If you only know what type of value you want, then you need to study on Loops + String functions to enumerate through the array and search its values.

http://www.hiddensoft.com/wiki/Arrays

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

If you know the index number then it would look something like $array[$index_number].

If you only know what type of value you want, then you need to study on Loops + String functions to enumerate through the array and search its values.

http://www.hiddensoft.com/wiki/Arrays

I've checked the faq, thanks for the link, it's very useful.

However, I couldn't find out how to get the string I need.

My code looks like this:

#Include <IE.au3>
#include <Array.au3>
#include <ExcelCOM_UDF.au3>

Global $aTableData[25]
$excelss="template.xls"
$excel=_ExcelAttach($excelss,"FileName")
$oIE = _IECreate ("http://www.petrolprices.com/")
_IELoadWait ($oIE)
WinSetState("","",@SW_MAXIMIZE)

$searchfld=_IEGetObjByName($oIE,"search")
_IEFormElementSetValue ($searchfld, "heathrow")
$searchfld.Select
send("{enter}")
_IELoadWait ($oIE)
;$price=_IEGetObjById($oIE,4)

$oTable = _IETableGetCollection ($oIE, 0)
$aTableData = _IETableWriteToArray ($oTable)
;_ArrayDisplay($aTableData)
;$lofasz=_ArrayToString($aTableData,"")
$mystring=$aTableData[1]
$excel.cells(4,2).select
$excel.cells(4,2)=$mystring

Of course this is not woring this way. Could you point me to the right direction?

Is there any other way to get the table as this array thing looks far too complicated to me...

Edited by b0ris
Link to comment
Share on other sites

At last I could figure out how to do this. Here's the working code:

#Include <IE.au3>
#include <Array.au3>
#include <ExcelCOM_UDF.au3>

Dim $searchfld
Dim $aTableData[10][20]
$excelss="weekly_blank_form.xls"
$excel=_ExcelAttach($excelss,"FileName")
$oIE = _IECreate ("http://www.petrolprices.com/")
_IELoadWait ($oIE)
WinSetState("","",@SW_MAXIMIZE)

$rowx=InputBox("Last Row","Enter last row number")
$row=5
Do
    $searchW=$excel.cells($row,5)
    $searchfld=_IEGetObjByName($oIE,"search")
    _IEFormElementSetValue ($searchfld, $searchW)
    $searchfld.Select
    send("{enter}")
    _IELoadWait ($oIE)

    $oTable = _IETableGetCollection ($oIE, 0)
    $aTableData = _IETableWriteToArray ($oTable)

    $gasprice=""
    $gaspricep = $aTableData[1][3]
    $gasprice=StringReplace($gaspricep, "p", "")
    $excel.cells($row,10)=$gasprice/100

    $dslprice=""
    $dslpricep = $aTableData[2][3]
    $dslprice=StringReplace($dslpricep, "p", "")
    $excel.cells($row,11)=$dslprice/100
    $row=$row+1
    _IENavigate($oIE,"http://www.petrolprices.com/")
    _IELoadWait ($oIE)
Until $row=$rowx+1

Cheers, and thanks for the help guys!

Edited by b0ris
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...