How can I view a [web]page's source right in terminal?

6,264

Many CLI/TUI browsers have source-viewing capability built in. In Lynx or Links, the keybinding for viewing source is \. In w3m it is v. For other browsers see the relevant documentation.

Share:
6,264

Related videos on Youtube

user3.1415927
Author by

user3.1415927

Updated on September 18, 2022

Comments

  • user3.1415927
    user3.1415927 over 1 year

    I've heard of lynx and links and other text-based browsers and those are fine, but I want get to the same information I'd see by executing View Page Source in Firefox for example. (IE and Chrome have their own similar functionality.)

    Is it possible to view this source via Terminal (or CLI) by browsing to the page in a terminal based application, or using commands? This isn't as simple as using wget on a page, as that won't fill scripted info (.cgi, .php, .js, etc.).

    • user3.1415927
      user3.1415927 about 6 years
      I have seen curl - how does this answer the question?
    • Attie
      Attie about 6 years
      It's not an "answer" per-se... As I said, you cannot get the original source for PHP files and the like from a correctly configured server... Even the view-source: prefix won't do that...
    • ivanivan
      ivanivan about 6 years
      Use wget with the -O - option. What @Attie says about grabbing server side source is correct - you will only see what the browser is sent. in the case of pages build with javascript, you MIGHT be able to see the js, or at least references to it with the URLs to again download and get it.
  • Unknow0059
    Unknow0059 about 4 years
    Does not get page source the same way the "View Page Source" button does. For example with a Steam store page. By using that button you can see the tags, but by using the script, you can't. I'm using my browser's UA string, and I've tried other strings.
  • Anaksunaman
    Anaksunaman about 4 years
    The methods described above can give the same output as view-source. However, they aren't immune to "outside" influence. Sites can tailor their responses before the page is even returned or browsers may may "modify" the page source themselves.
  • Anaksunaman
    Anaksunaman about 4 years
    "For example with a Steam store page. By using that button you can see the tags, but by using the script, you can't." - While it is true that Steam seems to be hard to replicate exactly, both methods described above will retrieve (at least) user-defined tags, general tags (e.g. Genre, Developer, etc.) and game pricing information from individual game pages (e.g. https://store.steampowered.com/app/123456/Game_Blah_Blah/). They both will also retrieve similar data from the main https://store.steampowered.com/ page. If you are having issues, you should probably clarify what those are.
  • Unknow0059
    Unknow0059 about 4 years
    The elements of the div class "glance_tags" do not appear using these methods. I had to use Selenium to get them. So now I'm working with that.
  • Anaksunaman
    Anaksunaman about 4 years
    Hmm. I couldn't replicate that issue. But yes, Selenium is the next step up. Glad you got things working.