我有点卡住了我的bash脚本。 我需要它login到基于https的网站…它需要使用用户名和密码login,然后它需要find一个特定的链接,链接文本总是相同的,但它指向的位置变化,它需要抓住那个位置并用wget下载它。
Anhbody有任何提示,我需要它是便携式,所以我不喜欢外部程序..
谢谢
bash
对于那些任务来说并不理想。 虽然你可以尝试像这样的:
curl --user name:password https://www.example.com/
但是,如果您需要在页面上找到链接,则可以尝试:
curl --user name:password https://www.example.com/ | grep WHAT_EVER_IDENTIFIES_LINK
然后再通过curl
得到它的输出。
但我会推荐像机械化的任务。 有python和Ruby等simillar库
此代码的作品登录到网站,但我不知道如何继续确定链接和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"