How do I enclose a field name to postForm with RCurl when the form has fields like those below?
<input id="form:checkEstrato" type="checkbox" name="form:checkEstrato" checked="checked" />
<input id="form:checkArea" type="checkbox" name="form:checkArea" checked="checked" />
if I try something like
if(url.exists(url))
results <- postForm(url,
form:evento="35",
form:area = "10")
I get
> if(url.exists(url))
+ results <- postForm(url,
+ form:evento="35",
Error: unexpected '=' in:
" results <- postForm(url,
form:evento="
> form:area = "10")
Error: unexpected ')' in " form:area = "10")"
in fact it was simple, although now I have to work it out why Rcurl doesn't get what I want.
At least to avoid de above error it as just a matter of enclosing the parameter name with quotes
if(url.exists(url))
results <- postForm(url,
'form:evento'="35",
'form:area' = "10")
Now lets move ahead trying to understanding what is being sent to server and why its not working the way I expected.
Related
I am learning how to fill forms and submit with rvest in R, and I got stucked when I want to search for ggplot tag in stackoverflow. This is my code:
url<-"https://stackoverflow.com/questions"
(session<-html_session("https://stackoverflow.com/questions"))
(form<-html_form(session)[[2]])
(filled_form<-set_values(form, tagQuery = "ggplot"))
searched<-submit_form(session, filled_form)
I've got the error:
Submitting with '<unnamed>'
Error in parse_url(url) : length(url) == 1 is not TRUE
Follow this question (rvest error on form submission) I tried several things to solve this, but I couldnt:
filled_form$fields[[13]]$name<-"submit"
filled_form$fields[[14]]$name<-"submit"
filled_form$fields[[13]]$type<-"button"
filled_form$fields[[14]]$type<-"button"
Any help guys
The search query is in html_form(session)[[1]]
As there is no submit button in this form :
<form> 'search' (GET /search)
<input text> 'q':
this workaround seems to work :
<form> 'search' (GET /search)
<input text> 'q':
<input submit> '':
Giving the following code sequence :
library(rvest)
url<-"https://stackoverflow.com/questions"
(session<-html_session("https://stackoverflow.com/questions"))
(form<-html_form(session)[[1]])
fake_submit_button <- list(name = NULL,
type = "submit",
value = NULL,
checked = NULL,
disabled = NULL,
readonly = NULL,
required = FALSE)
attr(fake_submit_button, "class") <- "input"
form[["fields"]][["submit"]] <- fake_submit_button
(filled_form<-set_values(form, q = "ggplot"))
searched<-submit_form(session, filled_form)
the problem is that the reply has a captcha :
searched$url
[1] "https://stackoverflow.com/nocaptcha?s=7291e7e6-9b8b-4b5f-bd1c-0f6890c23573"
You won't be able to handle this with rvest, but after clicking manually on the captcha you get the query you're looking for :
https://stackoverflow.com/search?q=ggplot
Probably much easier to use my other answer with:
read_html(paste0('https://stackoverflow.com/search?tab=newest&q=',search))
please I have a problem with the parameters of an action. Can someone help me? I'll explain:
I have an action "Etiquette (string nom_pharm, int numBon, int nbColis)" in the "Etiquetage" controller. In the view I have two input text for numBon and nbColis, I try to get them back to pass them in parameter but always the second one indicates that it is null, I use this line:
<input type="button" value="Ok" onclick="window.location = '#Url.Action("Etiquette", "Etiquetage",new { nom_pharm = #Model.PharmacieNom, numBon = " ", nbColis = " " })'+parseInt(document.getElementById('in').value), +parseInt(document.getElementById('bon').value)" />
Do you have an idea of the correct syntax?
The relative url you need is /Etiquetage/Etiquette?non_pharm={value of in}&numBon={value of bon}&nbColis={value of in}
but your code is generating this /Etiquetage/Etiquette?non_pharm={value}&numBon= &nbColis= {value of in}{value of bon}.
Your approach is a bit strange. A more conventional approach would be to use a form with a POST rather than a GET. Assumming you have a good reason for using javascript here for sending a GET request this code should work.
<input type="button"
value="Ok"
onclick="window.location = '#Url.Action("Etiquette", "Etiquetage")?non_pharm=#Model.PharmacieNom&numBon='
+ document.getElementById('bon').value + '&nbColis='
+ document.getElementById('in').value" />
Note I have assumed that 'bon' goes with numBon and 'in' goes with nbColis.
Because you are creating a string the parseInts are not needed.
I trying to produce this output character string
CONTAINS(ORIG_DOC,'SECTIONS("7 - Past Medical/Surgical History")(PRECISE FORM OF "DM", PRECISE FORM OF "DM2", "diabetes")') <> 0
using the paste function as below
paste("CONTAINS(ORIG_DOC,'SECTIONS("7 - Past Medical/Surgical History")(PRECISE FORM OF "DM", PRECISE FORM OF "DM2", "diabetes")') <> 0")
I am getting an error
Error: unexpected numeric constant in "paste("CONTAINS(ORIG_DOC,'SECTIONS("7"
Not sure what I am missing here, any help is much appreciated.
Escape all double-quotes " as \" and use noquote:
> txt = noquote(paste("CONTAINS(ORIG_DOC,'SECTIONS(\"7 - Past Medical/Surgical History\") (PRECISE FORM OF \"DM\", PRECISE FORM OF \"DM2\", \"diabetes\")') <> 0"))
> txt
[1] CONTAINS(ORIG_DOC,'SECTIONS("7 - Past Medical/Surgical History") (PRECISE FORM OF "DM", PRECISE FORM OF "DM2", "diabetes")') <> 0
>
I am modifying an asp.net page which has the following code:
<input type="button" id="room22SendEmail" name="room22SendEmail" value="Send" onclick="SendEmail('<%=mainValue%>');"/>
but there is an error after "SendMail('<%.." unterminated string constant. If I remove the single quotes I get a syntax error.
Whether it is
onclick="SendEmail(<%=#mainValue%>");'>
or
onclick="SendEmail(<%=mainValue%>");'>
I get the syntax error in the same places, marking the ( and )
I am trying to use Symfony 1.4's functional tests (sfTextFunctional) to verify the value of a textfield is as I expect. This is the html that is generated
<input type="text" maxlength="10" name="number_plant[1]" value="5" id="number_plant_1">
During the test I can set the value easily
setField('number_plant[1]', '5')->
And I have tried the following permutations of checkelement but they all return null
checkElement('number_plant[1]',"5")->
checkElement('number_plant_1',"5")->
checkElement('#number_plant_1',"5")->
checkElement('form input[type="text"][name="number_plant[1]"]',"5")->
Try something like:
checkElement('#number_plant_1[value="5"]')
EDIT: Apparently only this selector works as expected:
checkElement('form input[type="text"][name="number_plant[1]"][value="5"]')
(which is quite strange ;) )
This will check if an elemnt with id = "number_plant_1" and value = "5" exists on the page. As far as I know when you pass a string as the second parameter to checkElement it will try to match the content of the found element with the given string.