Skip to content

Instantly share code, notes, and snippets.

@saga
Created July 23, 2010 10:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saga/487246 to your computer and use it in GitHub Desktop.
Save saga/487246 to your computer and use it in GitHub Desktop.
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
import logging
from google.appengine.api import urlfetch
from BeautifulSoup import *
class SoapLinks(webapp.RequestHandler):
def get(self, url):
url = url.replace('%3A', ':', 1)
params = url.split('/')
del params[-1]
baseUrl = "/".join(params)
baseUrl = baseUrl + "/"
resultStr = ""
response = urlfetch.fetch(url, method=urlfetch.GET)
if response.status_code == 200:
content = response.content
resultList = list()
#logging.debug(r"SoapLinks get %s" % content)
self.response.headers['Content-Type'] = 'text/html;charset=utf-8'
soaplinkstmp = BeautifulSoup(content, parseOnlyThese=SoupStrainer('dd'))
for dda in soaplinkstmp:
if dda.contents[0].find("_img") >= 0:
self.response.out.write("<a href='%s'>%s</a>" % (dda.contents[0], dda.contents[0]))
self.response.out.write("<br />")
logging.debug(r"SoapLinks Tmp get %s", dda.contents[0])
self.response.out.write("<br />")
self.response.out.write("<br />")
self.response.out.write("<br />")
self.response.out.write("<br />")
for dda in soaplinkstmp:
if dda.contents[0].find("_img") >= 0:
thumb_url = dda.contents[0].replace('http://', '', 1)
self.response.out.write("<img src='http://cdn-cloud.appspot.com/a/%s?url=%s' />" % (thumb_url, dda.contents[0]))
self.response.out.write("<br />")
def main():
application = webapp.WSGIApplication(
[
(r'/soaplinks/(.*)', SoapLinks)],
debug=True)
run_wsgi_app(application)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment