setelah tadi kita belajar Di tutorial sy sebelumnya tentng pengenalan spynner,setup spynner,dan How to Touch jqeury,javascript n ajax
sekarang di tutorial ini saya akan memperlihatkan kekuatan spynner yang lainnya yaitu [Cooking your soup: parse the HTML] and [Snap shott]
wah apa lagi itu ??
kalian tau ?? bagi kalian yang sudah biasa dengan python ..kalian dapat melakukan tehnic parse HTML halaman Web dengan library parsing favorit kalian(BeautifulSoup, lxml,urllib,dll ...). Karena kita telah menggunakan Jquery untuk Javascript, rasanya hanya alami untuk bekerja dengan pyquery ..jadi di sini kita membutuhkan satu library python yaitu Pyquery
[http://pypi.python.org/pypi/pyquery] woow looks awaesome ...
So lets we Cooking a delicious soup ....
pertama tama kita mulai dengan script berikut untuk merequest source code (HTML) dari halaman web
Code:
#!/usr/bin/python
#Coder by jimmyromanticdevil
#Intro spynner Code Part 1
#Title : Cooking your soup: parse the HTML
#Tutorial Introduce spynner part 2
#Special thanks to 5ynl0rd,kiddies aka peneter,ne0_d4rk_fl00der,pyflux,pyfla,notradame_queen,vitadini,zee_eichel,The Witch,Oghie,Dr Crash,Parcomx,Gameove,Maxe,s3my0n & Ahmad Asto
#Thanks Comunity : All Tecon-crew and MEH [member n staff] & Void-labs developer Team..
import spynner
import pyquery
def Cookingsoup():
try:
url ="http://exploit-id.com/category/articles"
b.load(url)
b.soup.make_links_absolute(base_url=b.url)
parse = b.soup('#1022').html()
print parse
b.wait_page_load()
except Exception:
pass
if __name__ == '__main__':
try:
b = spynner.Browser()
b.debug_level = spynner.DEBUG
b.set_html_parser(pyquery.PyQuery)
b.create_webview()
b.show()
Cookingsoup()
except Exception ,err:
pass
-Penjelasan :
Nah mungkin ad yang terlihat baru di codenya dan ad yang terlihat tidak asing ...karena kali ini kita masak soup ....jadi kita perlu untuk menyiapkan bahannya : import pyquery ,b.set_html_parser(pyquery.PyQuery) nah di sini seperti sebelumnya kita mengabungkan/setup si pyquery ini dengan spynner ....
dan b.soup.make_links_absolute(base_url=b.url) dan parse = b.soup('#1022').html() dan di sinilah sedikit contoh saat memasak ..lolz ...saya akanmerequest source code (HTML) dari halaman web dengan struc
Code:
<div class="article" id="1022">
Yang akan menghasilkan saat kita mrequest :
Code:
<div class="articleContent">
<h3><a href="http://exploit-id.com/articles/dns-spoofing-with-scapy" title="DNS Spoofing With Scapy">DNS Spoofing With Scapy</a></h3>
<small>March 28, 2011 Author: <a href="http://exploit-id.com/author/yur4kh4" rel="tag">yur4kh4</a> <span class="views">Views: 97</span></small><p></p>
<div id="expand1022" style="display: none;"><p>View Code TXTbissmillah… ============================================= Malang Cyber Crew | indonesian cyber security ============================================= title : DNS spoofing with scapy auth0r : yur4kh4 blog :
http://www.devirakhjib.uni.cc/ mail : yur4kh4[at]yahoo[dot[com] date : 23-03-2011 Language : Indonesian[*]pembuka tulisan ini di buat semata-mata untuk pelajaran saja, tidak ada maksud untuk merusak & meningkatkan traffic cyber crime<a href="http://exploit-id.com/articles/dns-spoofing-with-scapy">Read more…</a></p>
</div>
</div>
<a title="show/hide" class="expandLink" id="expand1022_link" href="javascript: void(0);" onclick="toggle(this, 'expand1022');">+</a>
<div class="clear"></div>
Ok cukup jelaskan ....kl kurang cukup jelas silahkan nanti kalian berkomentar di bawah
Ok next mari kita memparse url yang ad di site ..
Code:
#!/usr/bin/python
#Coder by jimmyromanticdevil
#Intro spynner Code Part 1
#Title : Cooking your soup: parse the HTML
#Tutorial Introduce spynner part 3
#Special thanks to 5ynl0rd,kiddies aka peneter,ne0_d4rk_fl00der,pyflux,pyfla,notradame_queen,vitadini,zee_eichel,The Witch,Oghie,Dr Crash,Parcomx,Gameove,Maxe,s3my0n & Ahmad Asto
#Thanks Comunity : All Tecon-crew and MEH [member n staff] & Void-labs developer Team.."""
<a class="http" href="http://id.wikipedia.org/wiki/Python_(bahasa_pemrograman)">Wikipedia</a>
a.http
"""
import spynner
import pyquery
def Cookingsoup():
try:
url ="http://wiki.python.org/moin/IndonesianLanguage"
b.load(url)
b.soup.make_links_absolute(base_url=b.url)
parse = b.soup('a.http').attr('href')
print 'Urlnya adalah :',parse
b.wait_page_load()
except Exception:
pass
if __name__ == '__main__':
try:
b = spynner.Browser()
#b.debug_level = spynner.DEBUG
b.set_html_parser(pyquery.PyQuery)
b.create_webview()
b.show()
Cookingsoup()
except Exception ,err:
pass
Penjelasan code :
- b.soup('a.http').attr('href') : di sini saya mencari code html
Code:
<a> dengan class = 'http' trus dengan beratribt <href= ...
see very simpe parse html dengan library ini ...masih banyak lagi silahkan berkreasi sendiri yah ..di sini saya hanya menyediakan tutorial basicnya saja use ur logic then make your code
so what next ??
ok next kita akan mencoba mendownload sebuah file dari website
Code:
#!/usr/bin/python
#Coder by jimmyromanticdevil
#Intro spynner Code Part 2
#Title : Cooking your soup: parse the HTML
#Tutorial Introduce spynner part 2#Special thanks to 5ynl0rd,kiddies aka peneter,ne0_d4rk_fl00der,pyflux,pyfla,notradame_queen,vitadini,zee_eichel,The Witch,Oghie,Dr Crash,Parcomx,Gameove,rMaxe,s3my0n & Ahmad Asto
#Thanks Comunity : All Tecon-crew and MEH [member n staff] & Void-labs developer Team..
import spynner
import pyquery
def Cookingsoup():
try:
url ="http://wiki.python.org/moin/IndonesianLanguage"
b.load(url)
b.soup.make_links_absolute(base_url=b.url)
url = b.soup('img').attr('src')
images_ = b.download(url, open('img.jpg', "w"))
print 'Urlnya adalah :',url
b.wait_page_load()
except Exception:
pass
if __name__ == '__main__':
try:
b = spynner.Browser()
#b.debug_level = spynner.DEBUG
b.set_html_parser(pyquery.PyQuery)
b.create_webview()
b.show()
Cookingsoup()
except Exception ,err:
pass
-Penjelasan code :
di sini saya mencari dulu source untuk file gambarnya b.soup('img').attr('src') yang saya dapatkan yaitu :
Code:
<div id="logo"><a href="/moin/FrontPage"><img src="http://www.python.org/images/python-logo.gif" alt="Python" ></a></div>
trus setalah saya dapatkan url link imgnya ..dan sy mendownloadnya ..b.download(url, open('img.jpg', "w"))
Simple kan spynner is powerfull ..
kalian bisa melihat fungsi downloadnya di sni :
Code:
def download(self, url, outfd=None):
"""
Download a given URL using current cookies.
@param url: URL or path to download
@param outfd: Output file-like stream. If None, save file to disk
using standard download path (see L{click}).
@return: Bytes downloaded (None if something went wrong)
@note: If url is a path, the current base URL will be pre-appended.
nah sekarang apa lagi kemampuannya ??
Wait masih ad ....yaitu Technic Snap Shoot ..
ex :
b.snapshot(koordx1,y1,x2,y2)
ini struc codenya gue ambil di browser.py si spynner
Code:
def snapshot(self, box, format=QImage.Format_ARGB32):
"""
Take an image snapshot of the current frame.
@param box: 4-element tuple containing box to capture (x1, y1, x2, y2).
@param format: QImage format (see QImage::Format_*).
@return: A QImage image.
"""
x1, y1, x2, y2 = box
w, h = (x2 - x1), (y2 - y1)
image = QImage(QSize(x2, y2), format)
painter = QPainter(image)
self.webpage.mainFrame().render(painter)
#self.webpage.mainFrame().render(painter, QRegion(x1, y1, w, h))
painter.end()
return image.copy(x1, y1, w, h)
code kali ini saya akan menSnap shoot halaman web
see the powerfull
Code:
#!/usr/bin/python
#Coder by jimmyromanticdevil
#Intro spynner Code Part 3
#Title : Snap Shoot code
#Tutorial Introduce spynner part 2#Special thanks to 5ynl0rd,kiddies aka peneter,ne0_d4rk_fl00der,pyflux,pyfla,notradame_queen,vitadini,zee_eichel,The Witch,Oghie,Dr Crash,Parcomx,Gameove,Maxe,s3my0n & Ahmad Asto
#Thanks Comunity : All Tecon-crew and MEH [member n staff] & Void-labs developer Team..
import spynner
import pyquery
def Cookingsoup():
try:
url ="http://wiki.python.org/moin/IndonesianLanguage"
b.load(url)
b.soup.make_links_absolute(base_url=b.url)
urll = b.snapshot((400,500,520,710)).save('snapgambar.jpg')
b.wait_page_load()
except Exception:
pass
if __name__ == '__main__':
try:
b = spynner.Browser()
b.debug_level = spynner.DEBUG
b.set_html_parser(pyquery.PyQuery)
b.create_webview()
b.show()
Cookingsoup()
except Exception ,err:
pass
Penjelasan : urll = b.snapshot((400,500,520,710)).save('snapgambar.jpg ') seperti keterangan di struc libnya ..
snapshot pada kordinat 400,500,520,dan 710 (koordx1,y1,x2,y2)....dan save dengan nama snapgambar ..ini hanya basic sj ..so silahkan berkreasi sendiri yah use your logic n make your code bagi pada decaptcher udh kebayang untuk bypass session .......
lol ..
Ok saya kira cukup untuk tutorial dari saya tentang spynner kali ini .....
jadi bagi yang tertarik ngoprek ni lib silahkan berkreasi sendiri yah dengan library ini
semogah berguna .. kalau ad slh mohon maaf yah ...Comment me if i am wrong ..
lets learn together ...
Happy coding ..
thanks to my refrensi :
[http://code.google.com/p/spynner/wiki/README]