how can i Grab Source code & save it in text file - javascript

I need your help to grab the source code of the page & can save it in a text file.
What actually i want!!
Instead of doing the lot of work like, right click on the page then click on view source code then to copy & paste it in a text file...
I want to make a short, i want to put a link on the page, in which i need to grab a source code, so when i just click on that link let say "Download Code" it grabs the current page source code & save it in a .txt format.
Kindly help me how can i do this?? it would be great if i can achieve this by using a java script, i don't want to use server side programming language.
I tried data URI but dont get the exact what i need

I find some thing on the below link:
http://css-tricks.com/examples/ViewSourceButton/#

Related

How to make file/result downloadable in html

I will request you see this repo: https://github.com/imsikka/ArtGallery
I want to make the result downloadable using a download button, I know how to make a download button but I don't know how it will make the file downloadable, I need to link the button with a specific part code or what?
Well I really don't know how to do it i surfed the net but got nothin really helpful
You can upload the information you want to download on an uploader site and apply the download link to the button using
Maybe this way you can solve your problem
Info: Conclusion. In HTML, a button link to another page can be by using the tag, tag, and the tag. A link on a button is get by href=”” attribute of tag. The “type=button” and “onclick=link” attributes are used to create a link on the button.

Loading .txt content in HTML file? If not, then where?

Very new to code. Searching for 2 days has yielded no results and I've gone nearly mad.
I have this CSS designed bar that I use in my live streaming overlays. I'm trying to populate text from a local .txt, xml, or json file onto the bar. I just cant figure out how to call this text and then style it.
Why? I'd like to eventually write a python script/GUI that can read / write to the .txt file (if its json or xml, ill try to figure it out). Baby steps.
So far, everything is div boxes and a video that is clipped to create the black bar (its looped to look animated).
Using
embed src="txtfile.txt"
loads up the file, but I cant style it T_T. I would really appreciate the help!
Main question. With this file that I am opening locally - how can I (on the backend) select a text file to be read, and then style that text?
I really appreciate the help or even a nudge in the right direction. I am so lost.
You will probably need to use a server language. I recommend using PHP as you are new to code. First you will need to set up a PHP supported development server for developing. You can search how to do this yourself as its out of the scope of your question (WAMP/MAMP/XAMPP).
If you are using PHP as your server language. presuming txtfile.txt is located in the same directory as your CSS designed bar, you can do the following:
<?php
// specify txt file path
include 'txtfile.txt';
// store txt file contents as string
$my_string = file_get_contents('txtfile.txt');
?>
Then wherever you want the string to appear, just echo the variable. Here's an example:
<span class="myCustomClass"><?php echo $my_string; ?></span>
You can then style whatever class you gave it in CSS.
Oh, and remember to change the file extension to .php
You can also use other server languages to achieve this.
Alternatively, you could embed the txt file in an iframe, and place the iframe inside the element you want:
<iframe src='txtfile.txt' scrolling='no' frameborder='0'></iframe>
...and there are other ways, too! Look into using jQuery and AJAX as it may be easier to do without the hassle of using PHP. You can just load the text file via an AJAX call, insert it inside the document and then you can style the content with CSS.

Download a file using python from a webpage without opening the webpage

I was looking for a way to write a script that will download a file from a specific website but without opening the website itself. I want everything to happen in the background.
The website is morningstar and a specific link for the example is this one:
https://financials.morningstar.com/ratios/r.html?t=MSFT
in this page, there is a "Button" (it is not really declared as a button but as a Hyperlink, the <a> tag in HTML)
I added a photo in the bottom so you can see for yourself exactly the way they wrote the code.
Anyway, I saw that when I clicked the button the href attribute actually calls a javascript function which then creates the links from which the file will be downloaded.
I am looking for a way that I can write a script and give it the link I want, for example, the link above, and the script will download this specific CSV file from that page into a folder of my choice.
I was looking at some selenium tutorials but I couldn't find much help for my specific problem.
Here's an example I use:
import requests
url = 'http://via.placeholder.com/350x150'
dashboardFile = requests.get(url, allow_redirects=True)
open('d:/dev/projects/new-wave/dashboard.pdf', 'wb').write(dashboardFile .content)
Oh, and depending on the size of the file you would want to download in chunks. A quick search of: "python download large file in chunks" will help.

Selenium: Getting ultimate href/link without clicking on it when it's a javascript call

I am webscraping a long table of html links (allowed under ToS). However, all the links are javascript calls (href="javascript:;") so using get_attribute() to get the link will not work. I don't want to actually click on all the links since it will download a large pdf file for each one
Is it possible to get the ultimate href/link that is called, without actually clicking the link and downloading the file?
Thank you!
Yes, but not easy - you need to take a look at javascript beyond those links, probably the links are generated dynamically.
The idea of doing this is described here
What does href expression do?
In short: in HTML for <a> to render correctly you need to set href, but sometimes there is no direct link or it's calculated somehow - so you need to look at javascript code which performs handling of those links - probably it's some click event listener you need to find

How can I save the content inside an html frame that pops up when a link is clicked using greasemonkey?

I need to automate a process that involves getting data from a series of links on a website.
Greasemonkey could do the job, but I can't get the content from inside that link.
The link looks like this:
<a id="ctl00_main_gvPolite_ctl02_lbDetaliiPolita" title="Detalii polita" class="icon16 icon-detalii" href="javascript:__doPostBack('ctl00$main$gvPolite$ctl02$lbDetaliiPolita','')"></a>
This would be the important part: javascript:__doPostBack('ctl00$main$gvPolite$ctl02$lbDetaliiPolita','')
I can't find that function defined anywhere in the javascript, it's only used at various points.
A frame pops up over the website displaying the content I need. After I get it in a variable I can just send it to a script on my server for processing.
For anyone interested, I was missing an input called __VIEWSTATEENCRYPTED
It's further down the page in the source code, just include it in your $.post(); or whatever you use and it will work.
All credit goes to MaxArt for this one. Thank you!

Categories