我有一個大字符串(來自網頁的html代碼)。製作一個包含在一個大字符串中的鏈接數組
現在的問題是如何解析圖像的鏈接。
我想製作該網頁中所有圖像鏈接的數組。
我知道如何做到這一點我的java,但我不知道如何做解析字符串,並在shell中做字符串操作。我知道有很多技巧,我想這可以很容易完成。
到底我想是這樣的
#!/bin/bash
read BIG_STRING <<< $(curl some_web_page_with_links_to_images.com)
#parse the big string and fill the LINKS variable
# fill this with the links to image somewhow (.jpg and .png only)
#after the parsing the LINKS should look like this
LINKS=("www.asd.com/asd1.jpg" "www.asd.com/asd.jpg" "www.asd.com/asd2123.jpg")
#I need the parsing and to fill the LINKS variable with the links from the web page
# get length of an array
tLen=${#LINKS[@]}
for ((i=0; i<${tLen}; i++));
do
echo ${LINKS[$i]}
done
謝謝您的答覆,你救了我的挫折
'for url in「$ {LINKS [@]}」;做echo $ url; done'。但是,我認爲你不會從試圖在'bash'中解析HTML獲得任何東西。 – chepner 2012-07-13 15:03:07