Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export query_build and query_parse. #425

Open
jjesusfilho opened this issue Jan 12, 2024 · 3 comments
Open

Export query_build and query_parse. #425

jjesusfilho opened this issue Jan 12, 2024 · 3 comments
Labels
feature a feature request or enhancement url 👑

Comments

@jjesusfilho
Copy link

Functions query_build and query_parse are very useful in the day to day work of web scraping. I think it would be great if the they were exported.

@hadley
Copy link
Member

hadley commented Jan 12, 2024

What's stopping you from using req_url_query()? Do you have some sample code you can share?

@jjesusfilho
Copy link
Author

jjesusfilho commented Jan 16, 2024

When someone wants to scrape a web page that uses POST method, the first thing to do is to inspect how the form is built. When you copy the form, it comes as raw data: "x=value1&y=value2&z=value3". query_build is useful to convert it to a list to be used as body in POST request.

The other way around, though less frequent, is also possible, e.g., when you want to convert a list to raw data so you can use it as script in RSelenium:

library(RSelenium)
remDr <- remoteDriver$new()

remDr$open()

js <- "var xhr = new XMLHttpRequest();
xhr.open('POST', 'http://httpbin.org/post', false);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');

xhr.send('x=value1&y=value2&z=value3');
return xhr.response;"

remDr$executeScript(js)

@hadley hadley added the feature a feature request or enhancement label Jan 16, 2024
@hadley
Copy link
Member

hadley commented Jan 16, 2024

Ah, good point. Thanks!

@hadley hadley added the url 👑 label Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement url 👑
Projects
None yet
Development

No branches or pull requests

2 participants