2

Cómo puedo hacer la acción de copiar y pegar el CUrl generado de un request de una web de forma automatizado?, traté de hacer con selenium wire con python pero no puedo acceder a esa sección de la red.

Estuve investigando un poco DevTools de chrome en modo desarrollador, sin embargo no tuve éxito, agradeceré si me pueden recomendar alguna técnica, herramienta js, etc. Gracias

Algo así puedo acceder a la parte de BODY:

from seleniumwire import webdriver  # Import from seleniumwire

# Create a new instance of the Firefox driver
driver = webdriver.Chrome(executable_path="My-path-drive-chromiun")

# Go to the Google home page
driver.get('https://www.google.com')

# Access requests via the `requests` attribute
for request in driver.requests:
    if request.response:
        print("Body:", request.response.body)

Adjunto una referencia de la acción copiar curl de forma manual, referencia.

introducir la descripción de la imagen aquí

Información adicional: Video demo del proceso de copiado y pegado del curl forma manual

1 respuesta 1

0

Lo hice con selenium, ChromeDriverManager, pychrome y DevTools de Chrome:

import time
import pychrome
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

def output_on_start(**kwargs):
    print ("STARTED ", kwargs)

def output_on_end(**kwargs):
    print ("FINISHED ", kwargs)

options = webdriver.ChromeOptions()
options.add_argument("--remote-debugging-port=8000")
driver = webdriver.Chrome(ChromeDriverManager().install(), chrome_options=options)

dev_tools = pychrome.Browser(url="http://localhost:8000")
tab = dev_tools.list_tab()[0]
tab.start()

start = time.time()
print (int(time.time() - start))

tab.call_method("Network.emulateNetworkConditions",
                offline=False,
                latency=100,
                downloadThroughput=9375,
                uploadThroughput=3125,
                connectionType="cellular3g")

tab.call_method("Network.enable", _timeout=20)
tab.set_listener("Network.requestWillBeSent", output_on_start)
tab.set_listener("Network.responseReceived", output_on_end)

start = time.time()
driver.get("https://larepublica.pe/")

El anterior código me permite acceder a la petición de la red en tiempo real y puedo convertir eso en un Curl o un solicitud directo en python.

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.