#!/usr/bin/env bash
#############################################################################
###########################################################################
### Created by A.M.Danischewski (c) 2017+ v1.00
### Issues: If you find any issues emai1 me at my <first name> dot
### <my last name> at gmail dot com.
###
### This is a simple effective options handler, that easily and
### automatically handles long and short options. Hack away at it! =)
###
### E.g. options_handler.bsh -e e_value -l --super s_value of default
### options_handler.bsh --extended e_value dispersed -l -s s_value default value
### This program is free software: you can redistribute it and/or modify.
###########################################################################
#############################################################################
declare -a OPTIONS
declare -A OPTIONVALUES
declare -i DEFAULT_OPTION_SET=0
declare -r DEFAULT_INDEX="default"
### This is a commandline options handler, it loads two arrays the first
### array OPTIONS holds the OPTION FLAGS that were passed. The second
### array is an associative array that holds option arguments if any
### that were passed in.
### Note: This handler does not accept spaces in long option names.
function process_options() {
while (($#>0)); do
case "$1" in
-e|--extended)
OPTIONS+=("-e")
## No argument option.
#[[ ! "$2" =~ ^- ]] && OPTIONVALUES["-e"]="$2" && shift
;;
-s|--super)
OPTIONS+=("-s")
[[ ! "$2" =~ ^- ]] && OPTIONVALUES["-s"]="$2" && shift
;;
-l|--longoption)
OPTIONS+=("-l")
[[ ! "$2" =~ ^- ]] && OPTIONVALUES["-l"]="$2" && shift
;;
--default)
;&
*)
if [[ "$1" =~ ^- ]]; then ## Handle unexpected options.
echo "*** Error option $1 not found" >&2
## Add your logic.
shift
fi
## Handle the default argument.
((! ${DEFAULT_OPTION_SET})) && OPTIONS+=("${DEFAULT_INDEX}") && DEFAULT_OPTION_SET=1
while [[ ! "$1" =~ ^- ]] && [[ $# -gt 0 ]]; do ## Look ma, no quotes. o_0
OPTIONVALUES["${DEFAULT_INDEX}"]+=" ${1}" && shift
done
[[ "$1" =~ ^- ]] && continue ## We have a flag again, skip shifting.
;;
esac
shift ## Shift to next option.
done
}
function print_options() {
for a in ${OPTIONS[@]}; do
echo "Got: $a with arg: ${OPTIONVALUES[${a}]}"
done
}
process_options "$@"
print_options
exit 0
Sunday, July 16, 2017
Bash Options Handler
Sunday, June 25, 2017
Dual Booting - Ubuntu w/Windows 10 Easy
How to dual boot an existing Windows 10 with an external hard drive.
Tested on the ASUS E200HA / Windows 10 / Ubuntu 17.04.
First download and create a bootable USB drive with Ubuntu 17.04 (tested)
or whatever your favorite Linux distro that has UEFI support is;
this tutorial will reference Debian commands, map them as necessary.
Step 1 - Enter the BIOS - Keep tapping F2 when the computer first starts -- otherwise, if it still boots Windows 10 go to Settings->Update & security->
Recovery->Advanced startup->Restart Now ->Troubleshoot->Advanced Options->UEFI Firmware Settings->Restart
Step 2 - In the BIOS, disable Fast Boot and disable Windows from the
Boot Priority List (anything else or bust)
Step 3 - Insert the USB and when the computer starts enter the BIOS
(hit F2 when starting on the Asus E200HA) Select from the
Override Boot Manager options the USB stick and boot your Linux distro,
get wifi set up and run $> sudo apt-get update
Step 4 - Attach the external hard drive, format as necessary with an
ext 4 partition for the Linux installation, or you can wait and allow
the installation software do it for you.
Step 5 - Install Linux to the external hard drive, on the screen where
it asks where you want to put the software on the Ubuntu installation
install workflow -- select SOMETHING ELSE (so you can get to the disk
formatting screens) IMPORTANT -- where it says "Device for bootloader
installation", look at the list of drives above and select from the drop
down list the same partition that has the label in the list above of
Windows Boot Manager efi. That's the partition we need to install our
bootloader to. Make sure you have at least one formatted ext4 partition
and have the mount point /. Finish installing Linux to your external
hard drive.
Step 6 - After the installation completes, type $> mount to see where
your external hard drive is mounted if it's not /target, then unmount it
$> sudo umount /dev/sda1 (if that's what it is). If it's not already mounted
on /target create a new directory on the root /:
Note: If you created other partitions make sure to unmount them and move
all the mounts to under /target (so the chroot kernel can see them).
$> sudo mkdir -p /target
Then mount sda on /target:
$> sudo mount /dev/sda1 /target
Then bind mount the critical directories:
$> for a in /sys /proc /run /dev; do sudo mount --bind "$a" "/target${a}"; done
Then mount the EFI directory, use gparted to locate the
Windows Boot Manager efi partition :
$> sudo mount /dev/sdXY /target/boot/efi
Chroot to the new install:
$> sudo chroot /target
On chroot:
$> sudo apt-get update
$> sudo apt-get install grub2
$> sudo update-grub2
$> exit
Reboot:
$> echo Cross fingers =\) && reboot
Step 7 -- Quickly yank the USB thumbdrive out before the computer gets
started (to make sure the USB hardware addresses don't screw anything
up). Your computer should hopefully automatically bring you back into
Ubuntu this time on the external hard drive no longer the USB thumbdrive.
Re-run an update of grub2:
$> sudo apt-get update
$> sudo update-grub2
DONE.
Step 8 - You should now be able to reboot with the external hardrive attached and it will go to the Ubuntu Grub2 bootloader, thereafter that you can select Windows Boot Manager and get into Windows 10 if you need to. If you don't have your external hard drive then you can still get to Windows 10 by going into the BIOS (hit F2) and select from the Boot Override options the Windows Boot Manager. Enjoy.
Tested on the ASUS E200HA / Windows 10 / Ubuntu 17.04.
First download and create a bootable USB drive with Ubuntu 17.04 (tested)
or whatever your favorite Linux distro that has UEFI support is;
this tutorial will reference Debian commands, map them as necessary.
Step 1 - Enter the BIOS - Keep tapping F2 when the computer first starts -- otherwise, if it still boots Windows 10 go to Settings->Update & security->
Recovery->Advanced startup->Restart Now ->Troubleshoot->Advanced Options->UEFI Firmware Settings->Restart
Step 2 - In the BIOS, disable Fast Boot and disable Windows from the
Boot Priority List (anything else or bust)
Step 3 - Insert the USB and when the computer starts enter the BIOS
(hit F2 when starting on the Asus E200HA) Select from the
Override Boot Manager options the USB stick and boot your Linux distro,
get wifi set up and run $> sudo apt-get update
Step 4 - Attach the external hard drive, format as necessary with an
ext 4 partition for the Linux installation, or you can wait and allow
the installation software do it for you.
Step 5 - Install Linux to the external hard drive, on the screen where
it asks where you want to put the software on the Ubuntu installation
install workflow -- select SOMETHING ELSE (so you can get to the disk
formatting screens) IMPORTANT -- where it says "Device for bootloader
installation", look at the list of drives above and select from the drop
down list the same partition that has the label in the list above of
Windows Boot Manager efi. That's the partition we need to install our
bootloader to. Make sure you have at least one formatted ext4 partition
and have the mount point /. Finish installing Linux to your external
hard drive.
Step 6 - After the installation completes, type $> mount to see where
your external hard drive is mounted if it's not /target, then unmount it
$> sudo umount /dev/sda1 (if that's what it is). If it's not already mounted
on /target create a new directory on the root /:
Note: If you created other partitions make sure to unmount them and move
all the mounts to under /target (so the chroot kernel can see them).
$> sudo mkdir -p /target
Then mount sda on /target:
$> sudo mount /dev/sda1 /target
Then bind mount the critical directories:
$> for a in /sys /proc /run /dev; do sudo mount --bind "$a" "/target${a}"; done
Then mount the EFI directory, use gparted to locate the
Windows Boot Manager efi partition :
$> sudo mount /dev/sdXY /target/boot/efi
Chroot to the new install:
$> sudo chroot /target
On chroot:
$> sudo apt-get update
$> sudo apt-get install grub2
$> sudo update-grub2
$> exit
Reboot:
$> echo Cross fingers =\) && reboot
Step 7 -- Quickly yank the USB thumbdrive out before the computer gets
started (to make sure the USB hardware addresses don't screw anything
up). Your computer should hopefully automatically bring you back into
Ubuntu this time on the external hard drive no longer the USB thumbdrive.
Re-run an update of grub2:
$> sudo apt-get update
$> sudo update-grub2
DONE.
Step 8 - You should now be able to reboot with the external hardrive attached and it will go to the Ubuntu Grub2 bootloader, thereafter that you can select Windows Boot Manager and get into Windows 10 if you need to. If you don't have your external hard drive then you can still get to Windows 10 by going into the BIOS (hit F2) and select from the Boot Override options the Windows Boot Manager. Enjoy.
Wednesday, February 8, 2017
Grab Rickroll Images - Quick w/out the Clicks
#!/usr/bin/env bash
#############################################################################
###########################################################################
### Created by A.M.Danischewski (c) 2017+ v1.00
### Issues: If you find any issues emai1 me at my <first name> dot
### <my last name> at gmail dot com.
###
### This is a simple program intended to grab the oft rickroll'd images from
### those sensationalist click-through image sites.
###
### This program requires (to work to full capacity) by default:
### curl, wget, sed, grep, uniq, sort
###
### This program is free software: you can redistribute it and/or modify
### it under the terms of the GNU General Public License as published by
### the Free Software Foundation, either version 3 of the License, or
### (at your option) any later version.
###
### This program is distributed in the hope that it will be useful,
### but WITHOUT ANY WARRANTY; without even the implied warranty of
### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
### GNU General Public License for more details.
###
### You should have received a copy of the GNU General Public License
### along with this program. If not, see <http://www.gnu.org/licenses/>.
###########################################################################
#############################################################################
url="${1:-http://allrookie.com/perfectly-timed-sports-moments-to-pump-you-up-for-the-upcoming-olympics/}"
html_prefix="${2:-rickroll}_"
master_file="${html_prefix}_master.txt"
start_index=${3:-1}
end_index=${4:-30}
cleanup_flag=${5:-1}
## Get all pages
for((a=${start_index};a<=${end_index};a++)); do
echo "Fetching: ${url%/}/${a}/ --> ${html_prefix}${a}.html ..."
curl -A mozilla -s "${url%/}/${a}/" > ${html_prefix}${a}.html
done
## Get all image links
while read b; do
sed 's/http/\nhttp/g' "${b}" | sed -r 's/(^.{250})(.*)/\1/g' | grep "^http" | sed -r 's/(PNG|GIF|JPEG|JPG)(.*)/\1/ig' | grep -Ei "(PNG|GIF|JPEG|JPG)$" >> "${master_file}.tmp"
done < <(ls ${html_prefix}*html)
## Uniq and sort the image links
sort "${master_file}.tmp" | uniq > "${master_file}"
rm -v "${master_file}.tmp"
## Fetch image links
while read c; do
wget --tries=3 -E -e robots=off -nc --random-wait --content-disposition --no-check-certificate -p --restrict-file-names=windows,lowercase,ascii --header "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:19.$(($RANDOM%10))) Gecko/20100101 Firefox/19.0" -nd "${c}"
done < "${master_file}"
((${cleanup_flag})) && rm -v "${html_prefix}"*html
exit 0
Wednesday, September 7, 2016
Animated Gifs -- Bash Alias
alias gifthis='_(){ (($#<1)) && echo "Usage: <output file> [glob frag (default:.png)] [delay (default:120)]" && return; convert -delay ${3:-120} -loop 0 *${2:-.png} "${1}";};_'
Thursday, August 25, 2016
Bash Parent/Child Pipe Inheritance Exploit
#!/bin/bash
ipaddr=${1}
rdlnk=$(readlink /proc/$$/fd/0)
user=""
passwd=""
function get_input() {
if grep -Eq "^pipe:|deleted" <<< "${rdlnk}" || [[ -p "${rdlnk}" ]]; then
while IFS= read -r piped_input || break; do
[[ -z "${ipaddr}" ]] && ipaddr="${piped_input}" && continue
[[ -z "${user}" ]] && user="${piped_input}" && continue
[[ -z "${passwd}" ]] && passwd="${piped_input}" && continue
done
fi
echo "Got that IP address you gave me to work on: ${ipaddr}"
[[ -n "${user}" ]] && echo "[... and that user: ${user}]"
[[ -n "${user}" ]] && echo "[... and that users password: ${passwd}]"
}
get_input
exit 0
$> process_ip.bsh 71.123.123.3
Got that IP address you gave me to work on: 71.123.123.3
But, put the parent into a piped loop and watch out:
$ echo -en "71.123.123.3\nroot\ntoor\n" | while read a; do echo "Parent loop, processing: ${a}"; grep -q '^[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}.[0-9]\{1,3\}' <<< "${a}" && ./process_ip.bsh "$a"; done
Parent loop, processing: 71.123.123.3
Got that IP address you gave me to work on: 71.123.123.3
[... and that user: root]
[... and that users password: toor]
Ouch. The parent only wanted to provide the IP Address from its pipe to the child. Presuming that the parent must maintain an open pipe with sensitive data in it at the time of the fork to the child process. How can this be prevented? Unfortunately, inheriting a parents fd's is a POSIX standard that is not easily moved. The best way to handle this is to provide yet another pipe on fd0 from the parent, since the most recent will be the one dup'd. E.g. ./process_ip.bsh "$a" < /dev/null
Thursday, July 14, 2016
Renaming files to crtime on Ext4
## Dates are of a format: FILE_20160612.txt yet the date portion is wrong
## it should reflect the creation date of the file. The creation date needs
## to be grabbed from Ext4 (pre-xstat) and the file moved to the proper file
## name. See the next blog entry for lscrtime.
while read a; do
fcrdt=$(lscrtime "${a}" | date -d"$(awk '$1="";1')" +%Y%m%d)
fprefix="$(sed 's/_.*$//' <<< "$a")"
mv "${a}" "${fprefix}_${fcrdt}.txt"
done < <(find . -type f)
Thursday, June 30, 2016
lscrtime -- Get crtime ext4 Creation Timestamp
Get the creation time, from ext4 using debugfs. To use just enter a regex that matches the files/directories in the cwd that you want to display. If you have multiple files with the same extension yet only want one, simply complete the regex with a $.
E.g. If these files are in the cwd: file_1 file_10 file_10000
To get the creation time of file10:
$> lscrtime file_10$
To list the creation time of all three:
$> lscrtime file_1 (if no other files are in the directory)
-- or -- (more specifically)
$> lscrtime 'file_1[0]{0,5}$'
E.g. If these files are in the cwd: file_1 file_10 file_10000
To get the creation time of file10:
$> lscrtime file_10$
To list the creation time of all three:
$> lscrtime file_1 (if no other files are in the directory)
-- or -- (more specifically)
$> lscrtime 'file_1[0]{0,5}$'
alias lscrtime='_() { local fs="";while IFS=" " read -d "" a b; do fs=$(df "${b:-.}"|tail -1|sed "s/ .*$//");crtime="$(sudo debugfs -R "stat <${a}>" "${fs}" 2>"${DISCARD_DEV}"|grep crtime|sed "s/.*-- //")"; echo "${b} ${crtime}"; done < <(find . -maxdepth 1 -regextype posix-extended -regex "^(./)*${1}.*" -printf "%i %f\0");};_'
Saturday, June 18, 2016
Removing Duplicate Files
#!/usr/bin/env bash
old_var="zzz"
var="xxx"
[ -n "${1}" ] && CMD="echo Dryrun: "
while read a; do
var="$(basename "${a}")"
[ "${var}" == "${old_var}" ] && ${CMD} rm -v "${a}" || old_var="${var}"
done < <(find . -type f | rev | sort -t'/' -k 1 | rev)
Sunday, April 17, 2016
Recursive Factorial in bc!
alias factorial='_() { var=${1}; echo -en "scale=25;\ndefine f (x) {if (x <= 1) return (1);\nreturn (f(x-1) * x);}\nf(${var})\nquit" | bc;};_'
Tuesday, April 5, 2016
Printing key-value pairs from Bash Associative array
#!/bin/bash
## Printing key-value pairs from a Bash associative array
unset myarr && declare -A myarr
let myarr["eightytwo"]+=8
let myarr["eightytwo"]+=74
myarr["thirteen"]+=1
myarr["thirteen"]+=3
let myarr["fiftythree"]+=48
let myarr["fiftythree"]+=5
for a in "${!myarr[@]}"; do echo "${a}: ${myarr["$a"]}"; done
Thursday, March 31, 2016
Bash Dynamic Loops -- Read file daemon
#!/bin/bash
COND1="break"
COND2="sleep 1"
## Dynamically change the loop logic from continue reading, to read
## all data and break.
[[ -z "${1}" ]] && COND="${COND1}" || COND="${COND2}"
while IFS= read -d $'\n' -r a || ${COND}; do
[[ -n "$a" ]] && echo "curl -s http://foo.bar/some.php?id=${a}"
done < id_list.txt
exit 0
Monday, March 28, 2016
Replacing Nth Occurrence from End of Line via Sed
SEARCH="one"
SEARCHNEG=$(sed 's/./[^&]*/g' <<< "${SEARCH}")
OCCURRENCE=3
REPLACE="FOUR"
SED_DELIM=$'\001'
sed -r "s${SED_DELIM}${SEARCH}((${SEARCHNEG}${SEARCH}){$((${OCCURRENCE}-1))}${SEARCHNEG})\$${SED_DELIM}${REPLACE}\1${SED_DELIM}" <<< "one one two two one one three three one one"
Friday, February 26, 2016
Decoding Black Knight Satellite -- Recon
#!/usr/bin/env bash
#############################################################################
###########################################################################
### Created by A.M.Danischewski (c) 2016 v1.00
### Issues: If you find any issues emai1 me at my <first name> dot
### <my last name> at gmail dot com.
###
### This program is intended to facilitate the recording of the Live ISS
### feed at http://www.ustream.tv/channel/live-iss-stream
###
### I noticed that the downloaded files offered on the Ustream servers
### seldom matched what I was viewing on the realtime stream from the
### website.
###
### See the following for more background on the Black Knight Satellite:
### https://www.youtube.com/watch?v=3RmSKT-9u_A
### https://www.youtube.com/watch?v=eO6a_e2u0c4
###
### To use this software, configure the download location variable below
### and add the aliases to your ~/.bashrc file. Then periodically open a
### webbrowser to: http://www.ustream.tv/channel/live-iss-stream
###
### If you see anything interesting, type $> rbk and make sure the webbrowser
### window remains visible (it records exactly what you see on your desktop
### screen). When the anomolous/interesting activity is over, go back to
### the recording terminal window and hit Ctrl-C to stop the recording.
### Afterward you can view the recent recording by typing in $> vbk.
###
### Upload your findings to Youtube as soon as possible.
###
### This program requires (to work to full capacity) by default:
### bash, avconv/ffmpeg, vlc
###
### Other useful software, youtube-dl for downloading youtube videos:
### https://rg3.github.io/youtube-dl/
###
### This program is free software: you can redistribute it and/or modify
### it under the terms of the GNU General Public License as published by
### the Free Software Foundation, either version 3 of the License, or
### (at your option) any later version.
###
### This program is distributed in the hope that it will be useful,
### but WITHOUT ANY WARRANTY; without even the implied warranty of
### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
### GNU General Public License for more details.
###
###########################################################################
#############################################################################
######## ### CHANGE ### ### OUTPUT DIR ### CHANGE THIS ####
## Change the following to the location of a large drive where you
## want the desktop recordings to live.
##
declare OUTPUTDIR="/mnt/seagate1/ISS/" ### CHANGE THIS
##
#################### END CHANGE
## These should be sensible for most people.
declare FILE_PREFIX="ISS_$(date +%Y%m%d)"
declare RESOLUTION="1280x720"
declare FRAMERATE="25"
declare AVCONVPROG="$(which ffmpeg || which avconv)"
declare DISCARD_DEV=/dev/random ## If not on Linux, change to /dev/null
declare VIDEOCODEC="libx264"
## If you are on Crouton or other chroot, change this (E.g. ":1.0+0,0")
declare CAPTUREDISPLAY=":0.0+0,0"
declare OUTPUTSUFFIX="mkv"
function get_max_iss_seq() {
MAXSEQ=$( { ls -p "${OUTPUTDIR%/}/${FILE_PREFIX}"* | tr '.' '_' | grep -E "${FILE_PREFIX}_[0-9]*" | sort -n -t _ -k 3 | tail -1 | cut -d_ -f3; } 2>"${DISCARD_DEV}")
echo "$((${MAXSEQ}+1))"
}
function print_aliases() {
cat << EOF
alias go2iss='cd "${OUTPUTDIR}"'
alias rbk='${0} -r'
alias arbk='${0} -ar'
alias vbk='go2iss; vlc "\$(ls -tr ISS* | tail -1)"'
EOF
}
(($#==0)) && echo "Usage: ${0##*/} [-r (record)] [-ar (record with audio)] [-p (print aliases)]" && exit 0
[[ ! -z "${1}" && "${1}" =~ ^-p ]] && print_aliases && exit 0
[[ ! -z "${1}" && "${1}" =~ ^-r ]] && "${AVCONVPROG}" -f x11grab -r ${FRAMERATE} -s ${RESOLUTION} -i "${CAPTUREDISPLAY}" -vcodec ${VIDEOCODEC} -pre lossless_ultrafast -threads 0 "${OUTPUTDIR%/}/${FILE_PREFIX}_$(get_max_iss_seq).${OUTPUTSUFFIX}" && exit 0
[[ ! -z "${1}" && "${1}" =~ ^-ar ]] && "${AVCONVPROG}" -preset medium -f alsa -i pulse -f x11grab -r ${FRAMERATE} -s ${RESOLUTION} -i "${CAPTUREDISPLAY}" -vcodec ${VIDEOCODEC} -threads 0 -aq 10 -af "volume=volume=10dB:precision=fixed" -ar 44100 -crf 23 "${OUTPUTDIR%/}/${FILE_PREFIX}_$(get_max_iss_seq).${OUTPUTSUFFIX}" && exit 0
Monday, February 1, 2016
Print Greek in Bash
alias print_greek='declare -A na_array=(["0380"]=1 ["0381"]=1 ["0382"]=1 ["0383"]=1 ["038B"]=1 ["038D"]=1 ["0378"]=1 ["0379"]=1 ["037F"]=1 ["03A2"]=1 ); for uprefix in 037 038 039 03A 03B 03C 03D 03E 03F; do for usuffix in {0..9} {A..F}; do [[ -z $(echo "${na_array["${uprefix}${usuffix}"]+check}") ]] && printf "\u${uprefix}${usuffix}\n"; done; done;'
Sunday, January 31, 2016
Simple Webscraper with PhantomJs!
//////////////////////////////////////////////////////////
///// PhantomJS URL Scraper v.1.3 /////
//
// Copyrighted by +A.M.Danischewski 2016+ (c)
// This program may be reutilized without limits, provided this
// notice remain intact.
//
// Usage: phantomjs phantom_urls.js <URL> [["class"|"id"] [<query id/class name>]]
//
// Argument 1: URL -- "https://www.youtube.com/watch?v=8TniRMwL2Vg"
// Argument 2: "class" or "id"
// Argument 3: If Argument 2 was provided, "class name" or "id name"
//
// By default this program will display ALL urls from a user supplied URL.
// If a class name or id name is provided then only URL's from the class
// or id are displayed.
//
///////////////////////////////////
var page = require('webpage').create(),
system = require('system'),
address;
if (system.args.length === 1) {
console.log(' Usage: phantomjs phantom_urls.js <URL> [["class"|"id"] [<query id/class name>]]');
phantom.exit();
}
address = system.args[1];
querytype= system.args[2];
queryclass = system.args[3];
page.open(address, function(status) {
if (status !== 'success') {
console.log('Error loading address: '+address);
} else {
//console.log('Success! In loading address: '+address);
}
});
page.onConsoleMessage = function(msg) {
console.log(msg);
}
page.onLoadFinished = function(status) {
var dynclass="function() { window.class_urls = new Array(); window.class_urls_next=0; var listings = document.getElementsByClassName('"+queryclass+"'); for (var i=0; i < listings.length; i++) { var el = listings[i]; var ellnks=[].map.call(el.querySelectorAll('a'),function(link) {return link.getAttribute('href');}); var elhtml=el.innerHTML; window.class_urls.push(ellnks.join('\\n')); }; return window.class_urls;}";
var dynid="function() { window.id_urls = new Array(); window.id_urls_next=0; var listings = document.getElementById('"+queryclass+"'); var ellnks=[].map.call(listings.querySelectorAll('a'),function(link) {return link.getAttribute('href');}); var elhtml=listings.innerHTML; window.id_urls.push(ellnks.join('\\n')); return window.id_urls;}";
var allurls="function() { var links = page.evaluate(function() { return [].map.call(document.querySelectorAll('a'), function(link) { return link.getAttribute('href'); };); };); console.log(links.join('\\n')); }";
var page_eval_function="";
if (querytype === "class") {
console.log(page.evaluate(dynclass).toString().replace(/,/g, "\n"));
} else if (querytype === "id") {
console.log(page.evaluate(dynid).toString().replace(/,/g, "\n"));
} else {
var links = page.evaluate(function() {
return [].map.call(document.querySelectorAll('a'), function(link) {
return link.getAttribute('href');
});
});
console.log(links.join('\n'));
}
phantom.exit();
};
Subscribe to:
Posts (Atom)