I am new to Rust and trying out different projects to become more familiar with the language. As the title says I would like to retrieve the html source of a webpage. I am aware of rust-http but I am not sure how to use that library for this purpose
For a more detailed description of what I am trying to do:
Given some url: www.google.com
I would like the underlying HTML source.
I have looked at the Github Documentation of rust-http but the lack of docs have been confusing.
(answer moved from an edit to the question)
After playing around/searching more I finally was able to get what I wanted. Here is some code using Hyper that retrieves the source.
let req = request::Request::get(hyper::Url::parse("www.google.com").unwrap()).unwrap();
let res = req.start().unwrap()
.send().unwrap()
.read_to_string().unwrap();
println!("Response: {}", res);
What is wrong with using the options built into the browsers to display source code? E.g Chrome and Firefox: right click and select "View Page Source".
Related
Suppose, I have a failing test in only one of the browsers, where one of the css/html elements is "not found".
Screenshot looks okay. How can I get the html source of the current document to check?
Using Nightwatch's wrapper for selenium function source (DOC), this can be accomplished relatively easily.
For instance:
browser
.url("http://www.google.com")
.source((result) => {
// Source will be stored in result.value
console.log(result.value);
})
I have a set of html documents. According to the normal search, whenever a document is searched for, a set of relevant documents shows up, by clicking on which we are taken to the document details page. From this document details, we can do view in Browser. My clients want this search results link to take them directly to the View in Browser page, skipping the document details page for html documents. How can I achieve this?
I have a custom JavaScript which creates the html page. Can I modify the JS code, to produce this functionality?
Thanks in advance!
Assuming you are running a recent version of Alfresco, there is a hack and an proper way.
The code you want to tweak is in share/components/search/search.js.
renderCellDescription = function Search_renderCellDescription(elCell, oRecord, oColumn, oData)
{
// ...
// displayname and link to details page
var displayName = oRecord.getData("displayName");
var desc = '<h3 class="itemname">' + $html(displayName) + '';
// ...
}
For the proper way, try following http://blogs.alfresco.com/wp/developer/2012/05/22/customizing-share-javascript-widget-instantiation-part-1/
If this looks all Chinese to you, hack the file in place an keep a copy of the original. Drop the tweaked version in tomcat/shared/classes/components/search.
If you are not running a recent version of Alfresco, go staight for the hack.
I have a framework with Webdriver+testng.
I want the result of all the methods i have run, in html format with their status and screen capture link.
please let me know whts the way of doing this.
Thanks in advance.
You can make use of this, But this only for BDD styled stories. If you are looking for a plain web driver scripts, try this selenium loggers.
TestNG creates a report in HTML format in 'test-output' folder (or, if you're using testNG plugin in Eclipse, you can specify the path in Window-Preferences-testNG). The folder is created and rewritten after each run. Look for index.html there.
You can add custom information there using Reporter.log (from org.testng.Reporter), the information can be found after 'Reporter output' link in the report. So basically all you need is an #AfterMethod which will take the screenshot and embed it into the log. This discussion may help.
I had read somewhere and have now forgotten that upgrading to the new asynchronous code will not enable one to track actual clicks for downloading items when user stays on the same page and that for tracking that you need to use the old version of GA code.
My question is, is that still the case and does anyone have any other reasons for not upgrading to use the newer asynchronous tracking?
thanks
Hmm...are you sure the "old" version of GA automatically tracked downloads? AFAIK GA never automatically tracked download links, that you always had to attach GA code (like a _trackEvent call) to your links yourself. But in any case, it's pretty easy to do it yourself, so it's really not a big deal. Plus, you get lots of benefits upgrading, and one day it may not even be an option to stick with the old version...
If you have jQuery you can for example do this:
// file types you want to consider a download
var downloadFileTypes = ['pdf','doc','docx','mp4'];
$(document).ready(function() {
$('a').filter(function() {
var ext = $(this).attr('href').split('.').pop().toLowerCase();
return ( $.inArray(ext, downloadFileTypes )>-1 );
})
.click(function() {
_gaq.push(['_trackEvent', 'Downloads', $(this).attr('href')]);
});
});
If you do not have a framework like jQuery, you can still do this easy enough with .getElementsByTagName() and using regular loops and conditions instead of the jQuery conveniences like .filter and .inArray
edit: Some things to note about that example:
the jQuery code was an example to hook the GA code to standard links pointing to the file types you specify in downloadFiletypes. It will only apply to links that exist at the time the code is executed. If you have links that may be dynamically generated on the page later, consider looking into .on() instead of .click()
you will need to make tweaks to matching links you want to consider downloads if they do not point to regular files with extensions. For instance, some websites have a controller script that expects a parameter with an ID and it dynamically serves up a pdf or whatever..if your files are like this, you will have to alter the logic to look for that instead.
I am trying to load html file in CKEditor in asp.net but for some reason I don't know how to put the html code from the code behind file.
CKEditor1.FilebrowserBrowseUrl = url;
CKEditor1.BasePath = url;
CKEditor1.Text = content;
none of that helped
Any advice? Thanks in advance, Laziale
I'm not sure which version you are using, but let's suppose that it's 3.x. I was playing around with the control and didn't find any possible way of doing this from code behind. However, I managed to make it work like this:
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "fckInitialization", #"
window.onload = function () {
var oEditor = CKEDITOR.instances['" + txtPost.ClientID + #"'];
oEditor.insertHtml('<strong>This is a bold text.</strong>');
};
", true);
I tried it in IE 8 and the last version of Mozilla (I think it was 9) and it worked. I also tried the same thing, but instead of window.onload I used the jQuery $(document).ready() and it worked only in IE. The reason is that you have to wait for everything to load in order to use the functions from the CKEditor API. I played with Firebug and the insertHTML worked.
If you are using 2.x, you can see somewhere in Google the same approach, but with a different API. I just can't find the link right now.
Another problem will be here, as you may figure out, that if you want to initialize a long text, you will have to write everything in a script, which is not really nice.
Maybe a possible solution for you will be to convert the HTML to BBCode first and then just set the Text property. This, of course, depends on the way you use the control, because BBCode does not contain all possible tags, but you can always modify the bbcode plugin of CKEditor to meet your needs. And I tested it and it works.
PS. Probably you can do it with the JavaScript method and an AJAX call.
Hope this helps!
Assuming ckeditor is being initialized from a textarea field, you can simply populate the body of the textarea.