Webscrapping Loop to get table data

BalloutMoe

Board Regular
Joined
Jun 4, 2021
Messages
137
Office Version
  1. 365
Platform
  1. Windows
Hello All I am trying to get some data from a table on a website. I need some help the following is a sample of each transaction inside the table after being located by driver.FindElementById("account_history").

What I need is if the class="active_column date_c" . text is equal to a certain date for example "04/04/2022" To copy into the sheet
class="active_column date_c"
class="itemtype_c"
class="description_c"
class="red_color amount1_c" here however if the class is class="green_color amount1_c" then I would like to make the value into a negative number before placing it into the worksheet. I have the below code but I am stuck on how to proceed. This code prints all the information from the table into the worksheet with no adjustments at all.

Rich (BB code):
<tr id="transaction_2_126006020003330" clickeventnotsetted="1" style="" postingdate="04/04/2022" pagen="2" check_number="0" transactionid="2_126006020003330" transaction_row="" class="transaction_row bottom_border padding_top_bottom_8 transaction_row  odd" role="row">
    <td align="center" class="active_column date_c" style="position:relative">&nbsp;&nbsp;04/04/2022</td>
    <td class="itemtype_c">ACH Withdrawal</td>
    <td align="left" width="40%" class="description_c">WASTE CONNECTION-WEB_PAY</td>
    <td class="red_color amount1_c">$ 135.77</td>
    <td align="right" class="hide-on-sort">$ 451.86</td>
    <td class="end-icon"><img src="images/trans-ok.png"></td>
        <img src="images/trans-ok.png">
    </td>
</tr>

<tr id="transaction_2_126006020003331" clickeventnotsetted="1" style="" postingdate="04/04/2022" pagen="2" check_number="0" transactionid="2_126006020003331" transaction_row="" class="transaction_row bottom_border padding_top_bottom_8 transaction_row  even" role="row">
    <td align="center" class="active_column date_c" style="position:relative">&nbsp;&nbsp;04/04/2022</td>
    <td class="itemtype_c">ACH DEPOSIT</td>
    <td align="left" width="40%" class="description_c">AUTOZONE RETURN</td>
    <td class="green_color amount1_c" align="right">$ 9.59</td>    
    <td align="right" class="hide-on-sort">$ 451.86</td>
    <td class="end-icon"><img src="images/trans-ok.png"></td>
        <img src="images/trans-ok.png">
    </td>
</tr>

My code:
VBA Code:
Sub GetInformation()
Dim driver As New WebDriver
Dim TransTable As Selenium.WebElement
Dim AllRows As Selenium.WebElements
Dim SingleRow As Selenium.WebElement
Dim AllRowCells As Selenium.WebElements
Dim SingleCell As Selenium.WebElement

Dim objFSO As Scripting.FileSystemObject
Set objFSO = CreateObject("Scripting.FileSystemObject")

driver.Start "chrome", ""
driver.Get 
MsgBox "Login now and click OK when done."

driver.FindElementById("DataTables_Table_0_length").FindElementsByTag("option")(3).Click

Set TransTable = driver.FindElementById("account_history")
Set AllRows = TransTable.FindElementsByTag("tr")

For Each SingleRow In AllRows

    Set AllRowCells = SingleRow.FindElementsByTag("td")

    RowNum = RowNum + 1
    
    For Each SingleCell In AllRowCells
        ColNum = ColNum + 1
        Set TargetCell = ThisWorkbook.Worksheets(2).Cells(RowNum, ColNum)
        TargetCell.Value = SingleCell.Text
        
    Next SingleCell
    
    ColNum = 0
    
Next SingleRow

driver.FindElementById("dropdown5").Click

End Sub

Thank you
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
class="red_color amount1_c" here however if the class is class="green_color amount1_c" then I would like to make the value into a negative number before placing it into the worksheet.
Try something like this:
VBA Code:
    If SingleCell.Attribute("class") = "red_color amount1_c" Then
        TargetCell.Value = CCur(Replace(SingleCell.Text, "$", ""))
    ElseIf SingleCell.Attribute("class") = "green_color amount1_c" Then
        TargetCell.Value = -CCur(Replace(SingleCell.Text, "$", ""))
    Else
        TargetCell.Value = SingleCell.Text
    End If
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top