selenium 我想从ringba中提取数据

xuo3flqw  于 2022-12-29  发布在  其他
关注(0)|答案(1)|浏览(173)

这是ringba的链接。虽然它需要一个帐号登录。但我分享了一点html代码。
下面是代码:

<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>

下面是该表的屏幕截图。

你可以看到一个表,但它不在表标记内。他们使用divs。在所有的divs内有一个叫做caller id的东西。我想在caller id下所有的id。我怎样才能使用selenium实现这一点。我知道我的html非常混乱,但一点帮助对我来说是最好的。
这里我尝试:

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()

我发现来电显示列,但它的唯一来电显示在终端:(我不知道我怎么能做到这一点!!

xmd2e60i

xmd2e60i1#

我解决了这个问题。我试了这个代码:

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)

这让我打印我想要的。谢谢

相关问题