Python: Web Scraping with dynamic values

Asked

Viewed 166 times

0

I am learning about Web Scraping, I have already managed to do some actions but I came across problem in a dynamic page where values are changed every refresh.

Unfortunately I can not pass the access url because it is only internal, but it follows the html code of the page, the id and name values change constantly, so I thought to take the dv, but I was not successful. I’d like to give a "tick" on that radiobutton

<div class="clsCheckBoxRow"><
div class="dijitInline dijitRadio dijitRadioChecked">
    <input name="pOpt_N4eaf5820x6195143c_NS_" id="N4eaf5820x61951468_NS_" type="radio" role="radio" value="1" dv="Pesquisa por data de abertura (Criado em)" class="dijitCheckBoxInput" onclick="return PRMTUtils.F_OnChange(event, this);" onkeypress="return PRMTUtils.F_OnChange(event, this);" onfocus="return PRMTUtils.f_CheckboxOnFocus(this);" onblur="return PRMTUtils.f_CheckboxOnBlur(this);" aria-checked="false">
</div>
<label for="N4eaf5820x61951468_NS_" style="border: 0px none;">Pesquisa&nbsp;por&nbsp;data&nbsp;de&nbsp;abertura&nbsp;(Criado&nbsp;em)</label>

Follow the code I’m using so far:

# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
import base64
senha = b'criptografada'

browser = webdriver.Chrome('D:\\user\chromedriver.exe')
browser.get('url-interna')
browser.maximize_window()
time.sleep(2)

botao1 = browser.find_element_by_id('cmdOK').click()
time.sleep(2)

step1 = browser.find_element_by_name('CAMUsername').send_keys('teste')
time.sleep(2)

step2 = browser.find_element_by_name('CAMPassword').send_keys(base64.b64decode(senha).decode("utf-8", "ignore"))
time.sleep(2)

botao2 = browser.find_element_by_id('cmdOK').click()
time.sleep(10)

# -*- código a ser implementado para extrais as informações do radiobutton*-
step3 = browser.find_elements(By.ID,'PRMT_SV*')[1]
print (step3)


time.sleep(5)
browser.close()
browser.quit()
  • Name and id follow some pattern?

  • They follow this pattern withNS_ at the end, but for example they can change all the rest of the string, e.g.: "N4eaf5820x61951468_ns_" "N5agh6870x61951468_ns_" "F6crhf8650x64551454_ns_" E so on and on.

1 answer

1


For the HTML provided, try:

step3 = browser.find_element_by_css_selector('.dijitInline.dijitRadio.dijitRadioChecked input').click()
  • Me returns the error: Selenium.common.exceptions.Elementnotinteractableexception: Message: element not interactable

  • I just edited, maybe you didn’t get the updated code.

  • James still has the same error: raise exception_class(message, screen, stacktrace) Selenium.common.exceptions.Elementnotinteractableexception: Message: element not interactable (Session info: Chrome=78.0.3904.87) Stacktrace: Backtrace:

  • You know tell me if this field is visible on the screen?

  • James problem solved: step3 = browser.find_element_by_css_selector('.dijitInline.dijitRadio input'). click() I appreciate your help !

Browser other questions tagged

You are not signed in. Login or sign up in order to post.