I would like to open a webpage from groovy, dump the specified webpage and eventually dump the webpage behind an anchor tag.
Does anybody has some sample code for this?
here is a variation
println 'http://www.google.com'.toURL().text
This is a good example
http://docs.codehaus.org/display/GROOVY/Simple+file+download+from+URL
Basically you want to do something like
def data = new URL(feedUrl).getText()
Related
I would like to save part of the URL and I don't really know how to do it. I would like to save the part of the URL in a variable.
Anyone has an idea how to do it?
First, to get the current url, use
current_url = WebUI.getUrl()
Then you will need to use some kind of string manipulations to get the part that you need.
Katalon uses Groovy language, so you can read about the string methods here.
For example, if current_url='https://www.tutorialspoint.com/groovy/groovy_strings.htm' you wish to get only the part of the url after the last / try something like this:
split_url = current_url.split('/')
partial_url = split_url[split_url.size()-1]
println partial_url
The result of the above is "groovy_strings.htm".
I was wondering if there was a way to find a URL when I am missing the middle. For example, I know that the beginning will be https://welldressedwolf/products/
and the end will be pretty-things but I do not know the middle portion.
With javascript you can get the full URL using window.location.href
After that you can remove the parts you dont want and you will have the middle.
More info: https://www.w3schools.com/js/js_window_location.asp
If you're looking to manually look up the address of a page, you could do so with a google search that specifies the site.
Try a site specific google search using something like the following:
"pretty things" site:welldressedwolf.com
I am connecting to a webpage using HtmlUnit and I want to read the information inbetween the tags. I will demonstrate using some code. Lets suppose I have the following link:
Hello!
I would like to read the Hello that's in between, preferably saved into a String variable. Here is the code essential for the task
// Simulating a Chrome browser
WebClient webClient = new WebClient(BrowserVersion.CHROME);
loggedIn = webClient.getPage("random-page.com");
HtmlAnchor anchorLink = loggedIn.getAnchorByHref("/private-messages/inbox");
Now if I use anchorLink.toString() I get <a href="www.anypage.com"> from the previous example but nothing about the characters inbetween the tags. I have gone through the API and I can't seem to find anything useful. Any workarounds?
Would getTextContent() be what you are looking for?
I am trying to download an image and displaying it in a view in rails.
The reason why I want to download it is because the url contains some api-keys which I am not very fond of giving away.
The solution I have tried thus far is the following:
#Model.rb file
def getUrlMethod
someUrlToAPNGfile = "whatever.png"
file = Tempfile.new(['imageprependname', '.png'], :encoding => "ascii-8bit")
file.write(open(data).read)
return "#{Rails.application.config.action_mailer.default_url_options[:host]}#{file.path}"
end
#This seems to be downloading the image just fine. However the url that is returned does not point to a legal place
Under development I get this URL for the picture: localhost:3000/var/folders/18/94qgts592sq_yq45fnthpzxh0000gn/T/imageprependname20130827-97433-10esqxh.png
That image link does not point anywhere useful.
My theories to what might be wrong is:
The tempfile is deleted before the user can request it
The url points to the wrong place
The url is not a legal route in the routes file
A am currently not aware of any way to fix either of these. Any help?
By the way: I do not need to store the picture after I have displayed it, as it will be changing constantly from the source.
I can think of two options:
First, embed the image directly in the HTML documents, see
http://www.techerator.com/2011/12/how-to-embed-images-directly-into-your-html/
http://webcodertools.com/imagetobase64converter
Second, in the HTML documents, write the image tag as usual:
<img src="/remote_images/show/whatever.png" alt="whatever" />
Then you create a RemoteImages controller to process the requests for images. In the action show, the images will be downloaded and returned with send_data.
You don't have to manage temporary files with both of these options.
You can save the file anywhere in the public folder of the rails application. The right path would be something like this #{Rails.root}/public/myimages/<image_name>.png and then you can refer to it with a URL like this http://localhost:3000/myimages/<image_name>.png. Hope this will help.
how can I parse a web page which uses AJAX...
I will be more specific here. there is a website http://www.wordcount.org/main.php which gives the rank of a word according to it's usage.
for a given word, I want to retrieve it's rank...
how can I get it?
this is extremely important.. thank you in a advance...
That flash page calls the following URL to get the data: http://www.wordcount.org/dbquery.php?toFind=0&method=SEARCH%5FBY%5FINDEX
If you are using PHP, then do something like:
$url = 'http://www.wordcount.org/dbquery.php?toFind=0&method=SEARCH%5FBY%5FINDEX';
parse_str(file_get_contents($url), $dataArray);
You can use http://htmlunit.sourceforge.net/ - it simulates a browser behaviour, leaving you with a current DOM to inspect. If you're using Java, it is straightforward, for any of the .NET languages it works fine with IKVM.