Viewing CSV in Firefox - firefox

I'm working on a script that outputs CSV files, and it's a pain to try to open CSV every time I run the script to debug the next step. Is there a way to open CSV directly in FireFox. I know there's a plugin for JSON, but couldn't find a plugin for CSV

Answer:
for Firefox: https://github.com/okfn/mozilla-csv-viewer
for Chrome: https://github.com/rufuspollock/chrome-csv-viewer
(I am testing and can back in 2020)

The previously-mentioned Firefox add-on appears to be outdated. I found another plugin that might be something you are looking for.

If the header is served correctly, a simple preview as a text file might work directly, e.g.
https://raw.githubusercontent.com/plotly/datasets/master/mtcars.csv
Otherwise try to put view-source: before the address:
view-source:https://raw.githubusercontent.com/plotly/datasets/master/mtcars.csv

Firefox should be able to handle CSV content without a plug-in.
What content-type are you using in your script?
header("Content-type: application/csv");
header("Content-Disposition: attachment; filename=file.csv");

Related

"Printed" PDF from Firefox too big

I often "print" some webpages into pdf files. Therefore I created an own stylesheet for that webpages so I have only the text I need (I'm using the addon stylish for it).
The problem: If I save the page to a pdf file, it becomes relatively huge. Example: I copied the text to LibreOffice and exported it to a pdf file. The result: about 100kb. With Firefox: 1.8 MB!! And it's only text! (I need that small smize, because I have to email the files)
Does anyone know how I can reduce those files? Maybe with ghostscript or any other commandline-tool?
EDIT:
Sorry, forgot to say: I'm using a Mac!
OMG, I can't believe it!!! I found the solution: Removing the original stylesheets (manually with Firebug or with a greasemonkey script) of the page was the trick. I don't know, where the bug is (Firefox or Mac OS)... it seems, that the background-images of whatever are saved into the pdf, altough they are completely hidden via my stylesheet.
Thanks for your help!

Export all http requests on a specific page to txt/csv

I use SIEGE to test my web server performance. For a more realistic test the best way to go would be to have SIEGE hit the web page (website.com/our-company) and all static assets (.css, .js, .png, .jpg). Everything that you see on the firefox / chrome debbuing tools, except of course from resources loaded from external servers (cdn.facebook, apis.google.com).
I am running several tests so it is a pain to manually collect all asset urls. Is there a tool that I can use to load a web page and export the url for everything that was loaded?
This is firefox debugging. If I could export this to txt or csv, it would be perfect.
I tried CURL on debian CLI but I am no experct. Any tool will help, it does't have to be a plugin of Firefox / Chrome.
Best regards.
In Chrome you can export these data to a HAR file (it's JSON based) in one click. Go to "Network", right click and choose "Save as HAR with content".
Here's a free command line application to convert HAR files to CSV. Hope it helps.
http://www.yamamoto.com.ar/blog/?p=201
EDIT: added the project to GitHub:
https://github.com/spcgh0st/HarTools
On Windows you could use HttpWatch to do this with the free Basic Edition in IE or Firefox:
http://www.httpwatch.com/download/
The CSV export function will export the URLs and other fields to a CSV file.
** Disclaimer: This was posted by Simtec Limited the makers of HttpWatch **
Had the same requirement of exporting HAR files from Chrome DevTools or Firebug to do load testing with siege. Additionally, I wanted to replay POST requests too.
Choose one of these solutions:
hardy # https://github.com/nbibler/hardy - ruby script
har2siege # https://gist.github.com/photopresentr/7974747 - node.js (my script)
Nevermind.
Just fond out the very nive LiveHtttpHeaders extension for firefox.
Best regards.
As you guys know, the HAR file format is a JSON file. So... I looked for a JSON to CSV converter and found this:
https://json-csv.com/
This worked for my HAR file that I got from GTmetrix.com. Enjoy!
You can Export all Http requests from Chrome Developer console by going to the Network tab
select one of the requests in Network Tab
press Right Mouse Button
from PopUp menu select Copy -> Copy all as Har (Curl/Har/etc)
paste into file

How to download pdf file in ruby without .pdf in the link

I need to download a pdf from a website which does not provide a link ending with (.pdf) using ruby. Manually, when i click on the link to download the pdf, it takes me to a new page and the dialog box to save/open the file appears after some time.
Please help me in downloading the file.
The link
You an do this
require 'open-uri'
File.open('my_file_name.pdf', "wb") do |file|
file.write open('http://someurl.com/2013-1-2/somefile/download').read
end
I have been doing this for my projects and it works.
If you just need a simple ruby script to do it, I'd just run wget. Like this exec 'wget "http://path.to.the.file/and/some/params"'
At that point though, you might as well run wget.
The other way, is to just run a get on the page that you know the pdf is at
source = Net::HTTP.get("http://the.website.com", "/and/some/params")
There are a number of other http clients that you could use, but as long as you make a get request to the endpoint that the pdf is at, it should give you the raw data. Then you can just rename the file, and you'll have the pdf
In your case, I ran the following commands to get the pdf
wget http://www.lawcommission.gov.np/en/documents/prevailing-laws/constitution/func-download/129/chk,d8c4644b0f086a04d8d363cb86fb1647/no_html,1/
mv index.html thefile.pdf
Then open the pdf. Note that these are linux commands. If you want to get the file with a ruby script, you could use something like what I previously mentioned.
Update:
There is an added complication that was not initially stated, which is that the url to the pdf changes every time there is an update to the pdf. In order to make this work, you probably want to do something involving web scraping. I suggest nokogiri. This way you can look at the page where the download is and then perform a get request on the desired URL. Furthermore, the server that hosts the pdf is misconfigured, and breaks chrome within a few seconds of opening the page.
How to solve this problem: I went to the site, and refreshed it. Then broke the connection to the server (press the X where there would otherwise be a refresh button). Then right click next to the download link, and select inspect element. Then browse the dom to find something that is definitively identifying (like an id). Thankfully, I found something <strong id="telecharger"> Download</strong>. This means that you can use something like page.css('strong#telecharger')[0].parent['href'] This should give you a URL. Then you can perform a get request as described above. I don't have time to make the script for you (too much work to do), but this should be enough to solve the problem.

Display csv inside firefox browser

I need to open a csv file within firefox. By default, it asks me to choose a download location or to open it with an external program. However, regarding the context, I have to display it straight away inside the browser as plain text, without passing by the popup screen which asks me what to do with the file.
I tried to tweak the Firefox "mimetype.rdf" in order to force the content type "text/csv" to be opened in browser. However, I don't find much information about this file, so I was more or less guessing... This is what I came out with:
<RDF:Description RDF:about="urn:mimetype:text/csv"
NC:value="text/csv"
NC:editable="false"
NC:description="CSV page"
NC:fileExtensions="csv">
<NC:handlerProp RDF:resource="urn:mimetype:handler:text/plain"/>
</RDF:Description>
My idea was to force firefox to treat text/csv as text/plain. This code does not work. But anyway, I managed to force content type using "Mason" firefox extension. However, when the browser sees it as a text/plain, it propose me to open it with notepad or download, does not help me much.
I tried other content types, the text/html, text/xml, it always asks me to choose an external application or download.
I tried to use several extensions, "openInBrowser" and "ViewAsText" make me able to do what I want, but I have to explicitely go in a menu and click the "view as text in the browser", no possibility to set a behavior for the content type "text/csv".
How can I explain that I want all the "text/csv" to be opened inside firefox by default?
Any idea?
Thanks
You could have an upload field where the CSV file gets uploaded to the server. Using server-side code (ASPX for example) you could upload the file, then read the contents of the CSV file and display the results using a Response.Write to the browser.

How can I alter the default behavior of a link to an mp3 file?

I'd like to alter the default behavior of a link that points to an mp3 file. All major browsers always open and play this mp3 file in a new window, and I'd like instead that this file be offered as a download by the browser.
¿Any Idea?
Thanks!!
If you control the server hosting the mp3, try serving it as Content-Type: application/octet-stream. and Content-disposition: attachment.
If you don't have enough control to set the content header, you could provide instructions that say to "Right click and Save As...", I've seen a lot of web sites do this.

Resources