好的,所以我有以下脚本从网址列表(urls.txt)中抓取详细联系信息。当我直接从终端运行以下命令时,我会得到正确的结果
perl saxon-lint.pl --html --xpath 'string-join(//div[2]/div[2]/div[1]/div[2]/div[2])' http://url.com
但是,当我从脚本中调用上述命令时,得到的结果是“没有这样的文件或目录”
这是我的脚本的副本
#!/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
我尝试将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
提前致谢
不要在命令替换中加上双引号。
不是:
mydata=$("perl saxon-lint.pl --html --xpath 'string-join(//div[2]/div[2]/div[1]/div[2]/div[2])' $url ")
# .......^...........................................................................................^
但是这个:
mydata=$(perl saxon-lint.pl --html --xpath 'string-join(//div[2]/div[2]/div[1]/div[2]/div[2])' $url )
用双引号指示您bash在路径,空格和所有位置中查找名为“ perl saxon-lint.pl --html等”的程序,并且显然不存在这样的程序。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句