Example #1
0
 def parse_encoded_data(self, input_data):
     decoded_data = decompress(urlsafe_b64decode(
         input_data.encode('utf-8')))
     dict_data = {}
     for x, y in parse_qs(decoded_data).items():
         dict_data[x.decode('utf8')] = y[0].decode('utf8')
     self.parse_dict(dict_data)
Example #2
0
def response(resp):
    dom = html.fromstring(resp.text)

    results = []
    for element in dom.xpath('//div[@id="search"] //td'):
        link = element.xpath('./a')[0]

        google_url = urlparse(link.xpath('.//@href')[0])
        query = parse_qs(google_url.query)
        source_url = next(iter(query.get('q', [])), None)

        title_parts = element.xpath('./cite//following-sibling::*/text()')
        title_parts.extend(
            element.xpath('./cite//following-sibling::text()')[:-1])

        result = {
            'title': ''.join(title_parts),
            'content': '',
            'template': 'images.html',
            'url': source_url,
            'img_src': source_url,
            'thumbnail_src': next(iter(link.xpath('.//img //@src')), None)
        }

        if not source_url or not result['thumbnail_src']:
            continue

        results.append(result)
    return results
Example #3
0
def response(resp):
    dom = html.fromstring(resp.text)

    results = []
    for element in dom.xpath('//div[@id="search"] //td'):
        link = element.xpath('./a')[0]

        google_url = urlparse(link.xpath('.//@href')[0])
        query = parse_qs(google_url.query)
        source_url = next(iter(query.get('q', [])), None)

        title_parts = element.xpath('./cite//following-sibling::*/text()')
        title_parts.extend(element.xpath('./cite//following-sibling::text()')[:-1])

        result = {
            'title': ''.join(title_parts),
            'content': '',
            'template': 'images.html',
            'url': source_url,
            'img_src': source_url,
            'thumbnail_src': next(iter(link.xpath('.//img //@src')), None)
        }

        if not source_url or not result['thumbnail_src']:
            continue

        results.append(result)
    return results
Example #4
0
 def parse_encoded_data(self, input_data):
     """parse (base64) preferences from request (``flask.request.form['preferences']``)"""
     decoded_data = decompress(urlsafe_b64decode(input_data.encode('utf-8')))
     dict_data = {}
     for x, y in parse_qs(decoded_data).items():
         dict_data[x.decode('utf8')] = y[0].decode('utf8')
     self.parse_dict(dict_data)
Example #5
0
def response(resp):
    results = []

    dom = html.fromstring(resp.text)

    # parse results
    for img in dom.xpath('//a'):
        r = {
            'title': u' '.join(img.xpath('.//div[class="rg_ilmbg"]//text()')),
            'content': '',
            'template': 'images.html',
        }
        url = urlparse(img.xpath('.//@href')[0])
        query = parse_qs(url.query)
        r['url'] = query['imgrefurl'][0]
        r['img_src'] = query['imgurl'][0]
        r['thumbnail_src'] = r['img_src']
        # append result
        results.append(r)

    # return results
    return results
Example #6
0
 def parse_encoded_data(self, input_data):
     decoded_data = decompress(urlsafe_b64decode(input_data.encode('utf-8')))
     self.parse_dict({x: y[0] for x, y in parse_qs(unicode(decoded_data)).items()})
Example #7
0
 def parse_encoded_data(self, input_data):
     decoded_data = decompress(urlsafe_b64decode(input_data.encode('utf-8')))
     self.parse_dict({x: y[0] for x, y in parse_qs(unicode(decoded_data)).items()})