Sakib ovi
Sakib ovi

Reputation: 557

I want to scrape data from ringba

Here is the link of ringba. Though it needs an account for logging in. But I am sharing a little bit of html code.

here is the code:

<div role="row" row-index="0" aria-rowindex="4" row-id="RGB61B0990BC908B3F771E72B1C73CA6F168312F3E2V3FPC01" comp-id="10077" class="ag-row ag-row-focus ag-row-even ag-row-level-0 ag-row-group ag-row-group-contracted ag-row-position-absolute ag-row-first ag-row-last" aria-selected="false" style="height: 29.6px; transform: translateY(0px); " aria-label="Press SPACE to select this row.">
   <div tabindex="-1" unselectable="on" role="gridcell" aria-colindex="122" comp-id="10078" col-id="campaignName" class="ag-cell ag-cell-not-inline-editing ag-cell-auto-height ag-cell-value ag-cell-focus" style="width: 211px; left: 0px;"><span><span title="Click to Filter" class="filterable-cell contrast">ACA Inbound Exclusive</span></span></div>
   <div tabindex="-1" unselectable="on" role="gridcell" aria-colindex="123" comp-id="10079" col-id="publisherName" class="ag-cell ag-cell-not-inline-editing ag-cell-auto-height ag-cell-value" style="width: 211px; left: 211px;"><span><span title="Click to Filter" class="filterable-cell contrast">Asif Shaikat</span></span></div>
   <div tabindex="-1" unselectable="on" role="gridcell" aria-colindex="124" comp-id="10080" col-id="inboundPhoneNumber" class="ag-cell ag-cell-not-inline-editing ag-cell-auto-height ag-cell-value" style="width: 141px; left: 422px;"><span><span title="" class="filterable-cell ">+13372244354</span></span></div>
   <div tabindex="-1" unselectable="on" role="gridcell" aria-colindex="125" comp-id="10081" col-id="number" class="ag-cell ag-cell-not-inline-editing ag-cell-auto-height ag-cell-value" style="width: 141px; left: 563px;"><span><span title="Click to Filter" class="filterable-cell ">+18889842447</span></span></div>
   <div tabindex="-1" unselectable="on" role="gridcell" aria-colindex="126" comp-id="10082" col-id="timeToCallInSeconds" class="ag-cell ag-cell-not-inline-editing ag-cell-auto-height ag-right-aligned-cell ag-cell-value" style="width: 70px; left: 704px;"><span><span title="Click to Filter" class="filterable-cell ">00:00:00</span></span></div>
   <div tabindex="-1" unselectable="on" role="gridcell" aria-colindex="127" comp-id="10083" col-id="isDuplicate" class="ag-cell ag-cell-not-inline-editing ag-cell-auto-height ag-cell-value" style="width: 70px; left: 774px;"><span><span title="Click to Filter" class="filterable-cell ">Yes</span></span></div>
   <div tabindex="-1" unselectable="on" role="gridcell" aria-colindex="128" comp-id="10084" col-id="endCallSource" class="ag-cell ag-cell-not-inline-editing ag-cell-auto-height text-center ag-cell-value" style="width: 70px; left: 844px;"><span><span title="Target" class="filterable-cell fa fa-dot-circle-o"></span></span></div>
   <div tabindex="-1" unselectable="on" role="gridcell" aria-colindex="129" comp-id="10085" col-id="timeToConnectInSeconds" class="ag-cell ag-cell-not-inline-editing ag-cell-auto-height ag-right-aligned-cell ag-cell-value" style="width: 70px; left: 914px;"><span>00:00:00</span></div>
   <div tabindex="-1" unselectable="on" role="gridcell" aria-colindex="130" comp-id="10086" col-id="targetName" class="ag-cell ag-cell-not-inline-editing ag-cell-auto-height ag-cell-value" style="width: 211px; left: 984px;"><span><span title="Click to Filter" class="filterable-cell contrast">LGM 63</span></span></div>
   <div tabindex="-1" unselectable="on" role="gridcell" aria-colindex="131" comp-id="10087" col-id="conversionAmount" class="ag-cell ag-cell-not-inline-editing ag-cell-auto-height ag-right-aligned-cell ag-cell-value" style="width: 70px; left: 1195px;"><span></span></div>
   <div tabindex="-1" unselectable="on" role="gridcell" aria-colindex="132" comp-id="10088" col-id="payoutAmount" class="ag-cell ag-cell-not-inline-editing ag-cell-auto-height ag-right-aligned-cell ag-cell-value" style="width: 70px; left: 1265px;"><span></span></div>
   <div tabindex="-1" unselectable="on" role="gridcell" aria-colindex="133" comp-id="10089" col-id="callLengthInSeconds" class="ag-cell ag-cell-not-inline-editing ag-cell-auto-height ag-right-aligned-cell ag-cell-value" style="width: 70px; left: 1335px;"><span><span title="Click to Filter" class="filterable-cell ">00:00:02</span></span></div>
</div>

Here is the screenshot of the table.

enter image description here

As you can see a table but its not inside table tag. They are using divs. inside all the divs there is something called caller Id. I want all the ids under caller Id. How can I achieve that using selenium. I know my html is very messy but a little help will best for me.

Here what I tried:

import os
from selenium import webdriver
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver import ActionChains
import time
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait


drive = webdriver.Chrome()

drive.get(
    "https://app.ringba.com/#/login"
)
wait = WebDriverWait(drive, 25)
drive.maximize_window()
action = ActionChains(drive)
username = wait.until(EC.element_to_be_clickable((By.ID, "userName")))
# drive.find_element(By.ID, "userName")
username.click()

username.send_keys("")

password = wait.until(EC.element_to_be_clickable((By.ID, "password")))
password.click()
password.send_keys("")

submit = wait.until(EC.element_to_be_clickable((By.ID, "login-form-submit")))
submit.click()

report = wait.until(EC.element_to_be_clickable((
    By.CSS_SELECTOR, "a[ng-click='vm.reportsExpanded = !vm.reportsExpanded']"))).click()

default = wait.until(EC.element_to_be_clickable((
    By.CSS_SELECTOR, "span[title='Create a new custom Call Logs Report']"
))).click()

dateSelector = wait.until(EC.element_to_be_clickable((
    By.CSS_SELECTOR, "div[class='daterangepicker-btn m-b-10 reporting-settings-v2__date-picker btn m-l-10'] span"
))).click()

date = wait.until(EC.element_to_be_clickable((
    By.CSS_SELECTOR, "li[data-range-key='Last 2 days']"
))).click()


elements = wait.until(EC.presence_of_all_elements_located((By.XPATH, "//div[@col-id='inboundPhoneNumber']")))

events = []
for e in elements:
    events.append(e.text)
    print(events)

time.sleep(15)

drive.close()

I found the caller id column but its only caller Id in the terminal :( I dont know how can I achieve this!!

Upvotes: 2

Views: 94

Answers (1)

Sakib ovi
Sakib ovi

Reputation: 557

I solved the issue. I tried this code:

elements = wait.until(EC.presence_of_all_elements_located((By.XPATH, '//*[@id="main-content"]/div[3]/div/div/call-log-vue-container/div/div[2]/div[5]/div[2]/div/div/div[2]/div[2]/div[3]/div[2]/div/div/div')))

numbers = []
for e in elements:
    callIds = wait.until(EC.presence_of_all_elements_located((
       By.XPATH,
       "//div[@col-id='inboundPhoneNumber']"
        )))
    # print([d])
    for c in callIds:
        numbers.append(c.text)

this let me print what I want. Thanks

Upvotes: 2

Related Questions