好的,所以我有以下脚本可以从 url 列表 (urls.txt) 中抓取联系方式。当我直接从终端运行以下命令时,我得到了正确的结果
perl saxon-lint.pl --html --xpath 'string-join(//div[2]/div[2]/div[1]/div[2]/div[2])' http://url.com
Run Code Online (Sandbox Code Playgroud)
但是,当我从脚本中调用上述命令时,我得到“没有这样的文件或目录”结果
这是我的脚本的副本
#!/bin/bash
while read inputline
do
//Read the url from urls.txt
url="$(echo $inputline)"
//execute saxon-lint to grab the contents of the XPATH from the url within urls.txt
mydata=$("perl saxon-lint.pl --html --xpath 'string-join(//div[2]/div[2]/div[1]/div[2]/div[2])' $url ")
//output the result in myfile.csv
echo "$url,$mydata" >> myfile.csv
//wait 4 seconds
sleep 4
//move to the next url
done <urls.txt
Run Code Online (Sandbox Code Playgroud)
我曾尝试将 perl 更改为 ./ 但得到相同的结果
任何人都可以告诉我哪里出了问题,请
我收到的错误是
./script2.pl: line 6: ./saxon-lint.pl --html --xpath 'string-join(//div[2]/div[2]/div[1]/div[2]/div[2])' http://find.icaew.com/listings/view/listing_id/20669/avonhurst-chartered-accountants : No such file or directory
Run Code Online (Sandbox Code Playgroud)
提前致谢
不要在命令替换中放置双引号。
不是:
mydata=$("perl saxon-lint.pl --html --xpath 'string-join(//div[2]/div[2]/div[1]/div[2]/div[2])' $url ")
# .......^...........................................................................................^
Run Code Online (Sandbox Code Playgroud)
但是这个:
mydata=$(perl saxon-lint.pl --html --xpath 'string-join(//div[2]/div[2]/div[1]/div[2]/div[2])' $url )
Run Code Online (Sandbox Code Playgroud)
使用双引号,您指示 bash 在路径、空格和所有内容中查找名为“perl saxon-lint.pl --html etc etc”的程序,显然不存在这样的程序。
| 归档时间: |
|
| 查看次数: |
3871 次 |
| 最近记录: |