使用wget下载网页并定义新文件名

时间:2016-10-15 13:08:44

标签: bash wget

我需要使用wget在bash中编写脚本,下载已传递给参数的网页,然后脚本应将提取的页面放入新的 file.html 然后还在第二个文件中提取网页的所有标签,并仅保留网页的内容。

这是我的剧本的开头:

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

从第二部分开始,我被封锁了。

1 个答案:

答案 0 :(得分:1)

这将有效:

page="https://fr.wikipedia.org/wiki/Page_web"
wget -O file.html -r -np "$page"
  1. 变量分配:var_name=value=周围不允许空格)
  2. Bash不是PHP,$var=val不正确,var=val是。
  3. 使用双引号允许变量展开("$page"
  4. 来自wget手册:

    -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.