samedi 2 septembre 2017

Extract HTML text from a table and store text as a string variable.

Using a web bot programmed with VBA, I am trying to automate a process online. It requires me to search on an online database and then click a "details" button. The problem is. The button does not have any form of ID, class, source. It only has an Href.

<a href="/console/details/index/transid/1640597980"><img src="/images/details.gif" border="0" alt="Show Transaction Details"></a><img src="/images/details.gif" border="0" alt="Show Transaction Details">

The problem is the href is unique to each search i.e., I cannot call the href like I normally would. For example: --

  Call IE.Document.parentWindow.execScript("/console/details/index/transid/1640597980", "JavaScript")

--because the string of numbers in the last part of the href: "transid/##########" changes with every new search.

Now, I dont need to actually click the button to get where I want to go. I can navigate to the destination of the button by simply navigating to the database address

URL = "http://ift.tt/2wwhg5T"
IE.Navigate URL

So somehow I need to be able to extract the 10 digits that make up the last section of the href i.e., matching the destination button url.

Here is what I have to work with. The database search returns a table with the following headings.

enter image description here

The number of rows can vary but each observation under transaction ID contains the string of numbers I am looking for. But I cannot extract that string. I have been troubleshooting for hours and hours.

Using help from other users I have the following code so far:

    Dim T_val As Object
Dim T_id As Object
Dim Table_id As Object
Dim TR_id As Object
Dim TD_id As Object
Dim T_body As Object


Set Table_id = IE.Document.getElementsByTagName("TABLE").Item(2)
Set T_body = Table_id.getElementsByTagName("TBODY").Item(0)
Set TR_id = T_body.getElementsByTagName("TR").Item(2)
Set TD_id = TR_id.getElementsByTagName("TD").Item(2)
Set T_val = T_id.innerText

Is there any way someone can help me without having the source html code? I cannot post it because it contains confidential information.

Aucun commentaire:

Enregistrer un commentaire