Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open URL in Chrome & save its source code using Command prompt

I am having a hard time to find how to save the page as html or .txt using command line in Chrome Browser,

This is what I've done so far,

C:\Users\Cipher\AppData\Local\Google\Chrome\Application>chrome.exe --new-window
http://google.com

This command will open a new window of Chrome browser and visit google.com but i couldn't be able to figure our how can i save google.com as html or as txt file , is there anyway to do so using command prompt ?

like image 430
Sufiyan Ghori Avatar asked Mar 10 '13 14:03

Sufiyan Ghori


People also ask

Why URL is not opening in Chrome?

Check Your Internet Connection The reason why Chrome is not loading pages may be down to something as simple as unstable or lost internet connection. Ensure that you have an active data plan, and restart your internet connection. Also, try loading other browsers and apps such as Firefox and WhatsApp.

How do you open a URL?

Method 2 of 2: The easiest way to open a URL is to click or tap a link in an app or website. Scroll to the URL. Text URLs usually appear in a different color than the rest of the text. They may also display a picture from the website and/or a headline that describes the site.


1 Answers

You cannot perform the task you describe manually, but you can perform it using WebDriver automation.

Chrome can be remote controlled using an API called WebDriver (part of Selenium 2 automating suite). WebDrive has bindings for various programming languages, including e.g. JavaScript and Python.

Here is example code for Python (not tested):

from selenium import webdriver

driver = webdriver.Chrome('/path/to/chromedriver')  # Optional argument, if not specified will search path.
driver.get('http://www.google.com/');
html = driver.page_source
f = open("myhtml", "wt")
f.write(html)
f.close()

Orignal example

like image 186
Mikko Ohtamaa Avatar answered Nov 16 '22 04:11

Mikko Ohtamaa