I like to keep the day job fun and productive by semi automating the everyday tediousness of web development.
The main reason I use curl is to search a file to see if a webpage has the desired string or not.
Its nice to be able to stay on the commandline to do this as its quicker then the manual process of
- open chrome,
- right click,
- view source code,
- command f to find the string
- bang head against monitor
Running the curl function below allows me to open the returned html in my favourite code editor, Vim.
This way i can easily search the returned source code by simple typing '/string_name'.
function to add to bash_profile
#get and open webpage html
#provide url as param
#keep it simple - doesnt work if you make it too complicated
function get_html() {
cd ~/Downloads
rm curled_html.html
curl $1 -H "Cache-Control: no-cache, no-store, must-revalidate" -H "Pragma: no-cache" -H "Expires: 0" > curled_html.html
vim curled_html.html
}
Now run
get_html https://example.com
Top comments (5)
This feature is already built into vim (edit: via
netrw
plugin; if you start vim without built-in plugins viavim --clean
orvim -u NONE
then this will not work)::write /path/on/disk
:grep
,/
,?
, ...etc.:%! jq
(useful if you're interacting with a JSON API).Demo
that is really cool. I use Alfred instead of spotlight on my mac too. so now the process has become even faster
>vim https://example.com
i do get a warning about wget so i just need to hit enter before the html loads in vim. but all good. everyday things get a little bit better.
this is a really great way to do it. Fantastic tip.
Nice tip, but I'd be wary of that automatically download arbitrary data to specific, hard-coded paths and filenames... and even more wary of scripts which delete files in the same manner.
A safer and more flexible approach might be to just wrap the curl command, and then you can use pipe to redirect the output into whatever is most convenient for your needs -- vim, grep/egrep, write to disk, etc.
this looks fun. love your work. and your safety first approach.