Untitled

mail@pastecode.io avatar
unknown
python
7 months ago
1.8 kB
2
Indexable
Never
# pychrome version: 0.2.4
import pychrome
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

# Run Chrome as chrome.exe --remote-debugging-port=9222

chrome_options = Options()
chrome_options.add_experimental_option("debuggerAddress", "localhost:9222")
driver = webdriver.Chrome(options=chrome_options)

browser = pychrome.Browser(url="http://127.0.0.1:9222")

# Get a list of tab objects
tab_objects = browser.list_tab()

# Looking for url
tab_url = "https://justica.portaldasfinancas.gov.pt/vendaleilaoel/leilao/detalhe.html"

# Iterate through the tab objects and print the URLs
for tab in tab_objects:
    tab.start()

    # Get the current URL from the tab
    # We use 'Runtime.evaluate' to execute JavaScript in the context of the page to get the URL
    result = tab.Runtime.evaluate(expression="document.location.href")

    # Extract the URL from the result
    url = result.get('result', {}).get('value', 'No URL found')

    if(url == tab_url):

        # Now that we have found the correct tab, let's execute JavaScript to get the input value of the second div with ID "divValorLic"
        script = """
        var divElements = document.querySelectorAll("#divValorLic");
        if (divElements.length >= 2) {
            var inputElement = divElements[1].querySelector("input");
            var licitacaoActualo = inputElement ? inputElement.value : 'No input element found';
            inputValue;
        } else {
            'Second div with ID "divValorLic" not found';
        }
        """
        result = tab.Runtime.evaluate(expression=script)
        input_value = result.get('result', {}).get('value', 'No input value found')

        print("Input Value of Second divValorLic:", input_value)
        break


driver.quit()
Leave a Comment