PyDigg
Bu modül ile herhangi bir Digg haberinin kaynak adresini alabiliyorsunuz. Kodlara buradan ve aşağıdan ulaşabilirsiniz.
pydigg.py içeriği:
# -*- coding: utf-8 -*- """ {Digg.com haberlerinin kaynak adresini alabilen bir modül.} {Test Sürümü} Copyright (C) {5 Aralık 2007} {Ömer Ücel} omerucel@gmail.com 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 2 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 library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """ import re import urllib class PyDigg: def __init__(self,adres): self.adres = adres self.gercek_adres = "" # Digg içeriği alınıyor self.icerik = urllib.urlopen(self.adres).read() # Gerçek adres için içerik çözümleniyor self.cozumle() def cozumle(self): self.gercek_adres = re.search(" <h3 id=\"title\"><a href=\".*\">",self.icerik).group() self.gercek_adres = self.gercek_adres[24:len(self.gercek_adres)-2] self.gercek_adres </a></h3>
ornek.py içeriği:
# -*- coding: utf-8 -*- from pydigg import * print PyDigg("http://digg.com/programming/PHP_Part_2_Currency_Converter_with_Automatic_Conversion_Rates_via_XML").gercek_adres
pydigg.py sayfasında kullanılan urllib modülü yerine urllib2 modülünü kullanırsanız bazı sayfalarda çıkan karakter kodlama hatasını almassınız.
Comment by Ömer Ücel — December 11, 2007 @ 3:43 am