לדלג לתוכן

משתמש:שמוליק/batch-dl-cat.py

מתוך ויקיפדיה, האנציקלופדיה החופשית

"""

#"""
import json, urllib2, re
data = json.load(urllib2.urlopen(urllib2.Request("http://commons.wikimedia.org/w/api.php?action=query&generator=categorymembers&gcmtitle=Category:Hahnenkamm&format=json&limit=400")))["query"]["pages"]

def GetContent(url):
  req = urllib2.Request(url.encode('utf-8'))
  req.add_header('User-Agent', 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3')
  response = urllib2.urlopen(req)
  data=response.read()
  response.close()
  return data
                      
for id in data:
  content = GetContent("http://commons.wikimedia.org/wiki/"+data[id]["title"].replace(' ','_'))
  url = re.compile('<div class="fullImageLink" id="file"><a href="(.*?)">').findall(content)[0]
  print(url)

"""

"""