简体   繁体   中英

selenium or beautiful soup to get data from dynamic table cell

I am trying to get text of a field inside web table, data field is inside table cell and its dynamic.I am using python script for this task. I have tried it through below

1- get attributes using x path , innerText , innerHTML, textContent, value, resulting None or Html.
2 - beautiful soup  - Returning HTML and with lxml returning none

HTML:

<td>
<div class="fieldsbox" id="xfe54" style="visibility: visible;">
<input readonly="" isoutputcontrol="true" xformstype="output" id="policy_number"
 xql="tns:CHDRNUM" databoundelement="true" __parent="tblResults" class="input output" 
absolutexpath="tns:CHDRNUM" doebivalidate="false" title="Value for Policy No." style="" 
ref="tns:CHDRNUM" _intable="true"></div>
</td>

Beautiful soup

url = "https://cms.bharti-axagi.co.in/home/CMS/com/bagi/cms/Loginforms/CMS_LoginScreen.caf"
    crom_driver.get(url)
    time.sleep(5)
    content = crom_driver.page_source
    soup = bs(content, "html.parser")
    data = soup.findAll("table", {"id": "CMS_CLAIMS_DETAILSTable"})

    print(data)

Through XPATH

    previous_Claim_Policy =  crom_driver.find_element_by_xpath(xpath_string).get_attribute('value')

    previous_Claim_Policy_inner_text = crom_driver.find_element_by_xpath(xpath_string).get_attribute('innerText')

    previous_Claim_Policy_txt = crom_driver.find_element_by_xpath(xpath_string).text

    previous_Claim_Policy_txt_content = crom_driver.find_element_by_xpath(xpath_string).get_attribute('textContent')

    previous_Claim_Policy_txt_html_inner = crom_driver.find_element_by_xpath(xpath_string).get_attribute('innerHTML')

I tried by full x path and it worked out wiht get_attibute('value')

xpath_string=''/html/body/div[2]/div[3]/div/div[2]/fieldset/div/div/div[1]/div/div[2]/div/div/table/tbody/tr[2]/td[2]/div/input''

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM