user6037075
user6037075

Reputation:

Download a web page using wget and define a new filename

I need to write a script in bash using wget which download a web page which has been passed to an argument and then the script should put the extracted page in a new file.html and then also extract all the tags of the web page in a second file and keep only the content of the web page.

This is the beginning of my script :

#!/bin/bash
$page = "https://fr.wikipedia.org/wiki/Page_web"
wget -r  -np '$page' file.html

From the second part, I am blocked.

Upvotes: 1

Views: 106

Answers (1)

Jahid
Jahid

Reputation: 22438

This will work:

page="https://fr.wikipedia.org/wiki/Page_web"
wget -O file.html -r -np "$page"
  1. Variable assignment: var_name=value (no space allowed around =)
  2. Bash is not PHP, $var=val is not correct, var=val is.
  3. Use double quote to allow variable expansion ("$page")

From wget manual:

-O file

  --output-document=file

       The documents will not be written to the appropriate files, but all
       will be concatenated together and written to file.

Upvotes: 1

Related Questions