ویکی‌پدیا:درخواست‌های ربات/سایت دانلودر

از ویکی‌پدیا، دانشنامهٔ آزاد

این ربات برای دانلود سایت طراحی شده است.

#!/usr/bin/python
# -*- coding: utf-8  -*-
#
# Reza(User:reza1615), 2011
#
# Distributed under the terms of the CC-BY-SA 3.0 .
#coding:utf8
import urllib2,codecs
from BeautifulSoup import BeautifulSoup
filesample = 'FinallResult.txt'
text2 = codecs.open( filesample,'r' ,'utf8' )
text = text2.read()
list=text.split('href=')[1:]
for urlr in list:
    try:
        urlr=urlr.split('>')[0].replace('"','')
        
    #    urlr="http://iranshahrpedia.ir/wiki/fa/index.php?title=%D9%88%DB%8C%DA%98%D9%87:Subjectif&q=%D8%A7%D8%AB&cols=5&page="+str('11')+"&rows=500"
        page = urllib2.urlopen(urlr)
        soup = BeautifulSoup(page)
        if str(soup).find('<li>')!=-1:
            matn=str(soup).split('<li>')[1].split('</li>')[0].split('</a>')[1]
            matn=matn.strip()   
            title=str(soup).split('<span class="page-name">')[1].split('</span>')[0]
            title=title.strip()   
        else:
            continue
        text='xxx\nXXX'+title+'XXX\n'+matn+'\n'
        with codecs.open( 'FinallResult2.txt',mode = 'a',encoding = 'utf8' ) as f:# (6)-----Name of Text file that it will save as translation
                    f.write( text )
    except:
        continue