简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM