Click download button after setting a form with rvest in R

  Kiến thức lập trình

I am trying to make a semi-automatic app for downloading a pdf from a webpage, where data are set on a form automatically, then users have to solve a captcha and lastly a pdf should be downloaded, but I don’t know how to replicate the click on the download button, I guess there may be an easy solution without the need for running a selenium server, this is the code all the way to uploading the form, presenting the captcha and receiving the users input:

library(rvest)
library(magick)

mihtml = read_html("https://verificacfdi.facturaelectronica.sat.gob.mx/")

imgsrc = mihtml |> html_element("#ctl00_MainContent_ImgCaptcha") |>
  html_attr("src")
imagen = paste0("https://verificacfdi.facturaelectronica.sat.gob.mx/",
       imgsrc)
image_read(imagen)
captcha = readline()
search =  html_form(mihtml)[[1]] |>
  html_form_set("ctl00$MainContent$TxtUUID" = "1DF85D1E-D8A5-45BE-983B-581A941A25DA",
              "ctl00$MainContent$TxtRfcEmisor" = "APU640930KV9", 
              "ctl00$MainContent$TxtRfcReceptor" = "IEC7508071B2",
              "ctl00$MainContent$TxtCaptchaNumbers" = captcha)

resp = html_form_submit(search, submit = "ctl00$MainContent$BtnBusqueda")

# here I can see the table
resp |> read_html() |> 
  html_node(".table") |> html_table()

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

Click download button after setting a form with rvest in R

I am trying to make a semi-automatic app for downloading a pdf from a webpage, where data are set on a form automatically, then users have to solve a captcha and lastly a pdf should be downloaded, but I don’t know how to replicate the click on the download button, I guess there may be an easy solution without the need for running a selenium server, this is the code all the way to uploading the form, presenting the captcha and receiving the users input:

library(rvest)
library(magick)

mihtml = read_html("https://verificacfdi.facturaelectronica.sat.gob.mx/")

imgsrc = mihtml |> html_element("#ctl00_MainContent_ImgCaptcha") |>
  html_attr("src")
imagen = paste0("https://verificacfdi.facturaelectronica.sat.gob.mx/",
       imgsrc)
image_read(imagen)
captcha = readline()
search =  html_form(mihtml)[[1]] |>
  html_form_set("ctl00$MainContent$TxtUUID" = "1DF85D1E-D8A5-45BE-983B-581A941A25DA",
              "ctl00$MainContent$TxtRfcEmisor" = "APU640930KV9", 
              "ctl00$MainContent$TxtRfcReceptor" = "IEC7508071B2",
              "ctl00$MainContent$TxtCaptchaNumbers" = captcha)

resp = html_form_submit(search, submit = "ctl00$MainContent$BtnBusqueda")

# here I can see the table
resp |> read_html() |> 
  html_node(".table") |> html_table()

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT