Lets say you wanted to know how several instructables are doing. Did not take the time to make it with a gui. that is your homework. Just picked a few instructables from the first page as an example. You will want to create a data file with the urls or the web address of the instructables you have chosen. Right click on the links and copy link location and then paste it in your editor using the data file(Please see the prior instructables on page scraping if you have any questions).
idata: (Note: do not type in "[data]" or [/data] or you will get an error)
[data]
http://www.instructables.com/id/Program-an-ATtiny-with-Arduino/
http://www.instructables.com/id/Gut-Check-Fridge-a-Tweeting-and-Facebooking-Fri/
http://www.instructables.com/id/Air-quality-balloons/
http://www.instructables.com/id/Sun-Bottles/
http://www.instructables.com/id/Wrap-around-workbench-under-100/
http://www.instructables.com/id/Solar-PV-tracker/
[/data}
Then you need to create a program file to collect the data via web scraping. I did not go to the trouble to make it gui for simplicities sake.
iget.sh
[code]
#================================
#
# Instructablesnumbers catcher
#
#=================================
# Assignments
# --------------------------------
datafile="idata"
# the date
tmon=$(date +"%b")
tday=$(date +"%d")
echo "The views for $dj on $tmon $tday:"
#=================================
#
# Data input
#---------------------------------
while read line
do theurl=$line
# uncomment the following line if you want to see the url and or views
echo -n "$theurl"
# get total views
# elinks "$theurl" | grep "Total Views"
# get all the info
elinks "$theurl" | grep -m 2 Views
# just get numbers
# elinks "$theurl" | grep "Total Views" | cut -c 16-25
# Un remark the next line if you want it to be a bit more readable
# echo ""
done < $datafile
[/code]
Make it a program:
$ chmod +x iget.sh
Run it:
$ ./iget.sh
The views for on Oct 06:
http://www.instructables.com/id/Program-an-ATtiny-with-Arduino/
Total Views: 587
Today Views: 95
http://www.instructables.com/id/Gut-Check-Fridge-a-Tweeting-and-Facebooking-Fri/
Total Views: 618
Today Views: 608
http://www.instructables.com/id/Air-quality-balloons/
Total Views: 54,833
Today Views: 216
http://www.instructables.com/id/Sun-Bottles/
Total Views: 43,876
Today Views: 17
http://www.instructables.com/id/Wrap-around-workbench-under-100/
Total Views: 15,157
Today Views: 12
http://www.instructables.com/id/Solar-PV-tracker/
Total Views: 107,243
Today Views: 46
$ _
The following will save everything to a file if your want.
$ ./iget.sh >> datafile
A real time saver if you have many many instructables and do not want to go through each page to get the data. Follow up instructable: http://www.instructables.com/id/Getting-instructable-counts-continued/
Warning: Data may not be always up to date.
============================================================================
Mswindows:
-----------------------------------
Software needed:
Browser:
Elinks:
http://www.paehl.com/open_source/?TextBrowser_for_Windows:ELINKS_an_other_textbrowser
Grep
Grep from unxutils
http://downloads.sourceforge.net/project/unxutils/unxutils/current/UnxUtils.zip?r=&ts=1331135481&use_mirror=iweb
Qbasic from Microsoft.
http://www.microsoft.com
Winzip:
http://www.winzip.com/win/en/downwz.htm
------------
You will want to create a datafile with the urls of the instructables you want to check on:
idata: (Note: do not type in "[data]" or [/data] or you will get an error)
[data]
http://www.instructables.com/id/Program-an-ATtiny-with-Arduino/
http://www.instructables.com/id/Gut-Check-Fridge-a-Tweeting-and-Facebooking-Fri/
http://www.instructables.com/id/Air-quality-balloons/
http://www.instructables.com/id/Sun-Bottles/
http://www.instructables.com/id/Wrap-around-workbench-under-100/
http://www.instructables.com/id/Solar-PV-tracker/
[/data}
Here is the code. you will want to make a program file called scrape.bas. You will run it from qbasic.
scrape.bas(just use the lines between [code] and [/code])
[code]
OPEN "idata" FOR INPUT AS #1
while not (eof(1))
INPUT #1, a$
PRINT a$
b$ = "elinks " + a$ + " | grep Views:"
SHELL b$
wend
close #1
system
[/code]
Note: If you have freebasic for mswindows or freebasic for linux. the code will work on either machine. I suppose it would work on a Mac also if you had the appropriate basic language compiler. Love portable code!
Once you have created all the files and the prorgams you downloaded are accessible from the directory, you should be able to get a print out.
c:\> qbasic /run scrape.bas
Afterthought: probably could of used lynx instead.....
========================================================
Temp fix:
#================================
#
# Instructablesnumbers catcher
#
#=================================
# Assignments
# --------------------------------
szAnswer=$(zenity --file-selection --title="Select a iurl file to read")
datafile=$szAnswer
outfile="inumdata"
total=0
# the date
tmon=$(date +"%b")
tday=$(date +"%d")
echo "The views for $dj on $tmon $tday:" > $outfile
#=================================
#
# Data input
#---------------------------------
while read line
do theurl=$line
echo "$theurl"
# echo -n "$theurl'" >> $outfile
# get total views
# count=$(elinks "$theurl" | grep -m 1 "hits-count" | sed 's/[^0-9]*//g')
count=$(elinks "$theurl" | grep -m 1 "views" | sed 's/[^0-9]*//g')
# let total=$total+$count
echo "$count" >> $outfile
done < $datafile
# echo "total: $total" >> $outfile
zenity --text-info --filename=$outfile


































Visit Our Store »
Go Pro Today »




Sunshiine