felipehespanhol
felipehespanhol

Reputation: 41

Using special characters in open-uri requests

I'm using open-uri to get content from a page on the web to be used with nokogiri. I'm trying something like:

url = "http://pesquisa.bvsalud.org/portal/?output=site&lang=pt&from=0&sort=&format=summary&count=20&fb=&page=1&q=\"qualidade+de+vida\"&index=tw" response = open(url)

Then I get the error: URI::InvalidURIError: bad URI(is not URI?)

The catch is: I know I can use URI.encode(url) to prevent some special characters in the url, but the website I'm requesting doesn't give me the same response when I sanitize the url, it doesn't answer properly when using '%22' instead of double quotes..

How can I make such request using double quotes? Any other library that can do it? Open-uri doesn't accept that. I tryed to use the gems addressable-uri and eat, but I get the same error on both. :/

Upvotes: 2

Views: 620

Answers (1)

Suicidal Penguin
Suicidal Penguin

Reputation: 78

URI.encode('http://pesquisa.bvsalud.org/portal/?output=site&lang=pt&from=0&sort=&format=summary&count=20&fb=&page=1&q=\"qualidade+de+vida\"&index=tw')
=> "pesquisa.bvsalud.org/portal/?output=site&lang=pt&from=0&sort=&format=summary&count=20&fb=&page=1&q=%5C%22qualidade+de+vida%5C&index=tw"

Upvotes: 4

Related Questions