2012-08-07 67 views
2

我有點卡住了我的bash腳本。我需要它登錄到一個基於https的網站......它需要使用用戶名和密碼登錄,然後需要找到一個特定的鏈接,鏈接的文本總是相同的,但它指向的位置更改,它需要抓取該位置並使用wget下載。Bash腳本登錄網站並下載文件

Anhbody有什麼祕訣,我需要它是便攜式的,所以我不喜歡依靠外部程序..

謝謝

+0

在哪裏你卡住了?你能告訴我們一些代碼嗎? – 2012-08-07 06:46:48

+0

Bash沒有SSL支持,你必須使用* some *外部程序,或者使用SSL來破解自身(幾乎不是理論選項)。 – tripleee 2012-08-07 07:51:05

回答

4

bash是不理想的,一種任務。雖然你可以嘗試這樣的:

curl --user name:password https://www.example.com/ 

但是,如果你需要找到網頁上的鏈接,你可以嘗試:

curl --user name:password https://www.example.com/ | grep WHAT_EVER_IDENTIFIES_LINK 

然後把它通過curl的再次輸出。

但我會推薦一些類似於mechanize的任務。還有爲Python和Ruby等

2

此代碼登錄到網站,但我不知道如何進行識別鏈接和wget它呈三角圖書館...

#!/bin/bash 

#REQUIRED PARAMS 
username="" 
password="" 

#EXTRA OPTIONS 
uagent="Mozilla/5.0" #user agent (fake a browser) 
sleeptime=0 #add pause between requests 

touch "cookie.txt" #create a temp. cookie file 

#INITIAL PAGE 
echo "[+] Fetching" && sleep $sleeptime 
initpage=`curl -s -b "cookie.txt" -c "cookie.txt" -L --sslv3 -A "$uagent"    "https://ny2.free2surfvpn.com/?src=connect"` 
token=`echo "$initpage" | grep "authenticity_token" | sed -e 's/.*value="//' | sed -e 's/" \/>.*//'` 

#LOGIN 
echo "[+] Submitting the login form..." && sleep $sleeptime 
loginpage=`curl -s -b "cookie.txt" -c "cookie.txt" -L --sslv3 -A "$uagent" -d  "authenticity_token=$token&username=$username&password=$password"  "https://mobile.twitter.com/session"` 

#HOME PAGE 
echo "[+] Getting page" && sleep $sleeptime 
homepage=`curl -s -b "cookie.txt" -c "cookie.txt" -L -A "$uagent"  "https://ny2.free2surfvpn.com/?src=connect"` 

rm "cookie.txt"