~facundo/encuentro/trunk

« back to all changes in this revision

Viewing changes to server/get_bacua_episodes.py

  • Committer: Facundo Batista
  • Date: 2017-06-23 00:35:18 UTC
  • mto: This revision was merged to the branch mainline in revision 296.
  • Revision ID: facundo@taniquetil.com.ar-20170623003518-sv60l0eib3rjx882
Huge renewal refactor.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf8 -*-
2
 
 
3
 
# Copyright 2012-2014 Facundo Batista
 
1
# Copyright 2012-2017 Facundo Batista
4
2
#
5
3
# This program is free software: you can redistribute it and/or modify it
6
4
# under the terms of the GNU General Public License version 3, as published
21
19
import logging
22
20
import re
23
21
import sys
24
 
import urllib2
 
22
 
 
23
from urllib import request
25
24
 
26
25
from bs4 import BeautifulSoup
27
26
 
43
42
 
44
43
def scrap_list_page(html):
45
44
    """Scrap the list page."""
46
 
    pagina = re.compile('<p class="info_resultado_busca">([^"]*)</p>')
 
45
    pagina = re.compile(b'<p class="info_resultado_busca">([^"]*)</p>')
47
46
    m = pagina.search(html).group(1)
48
 
    s = re.sub('<[^<]+?>', '', m)
49
 
    t = re.compile('[0-9]+[0-9]')
 
47
    s = re.sub(b'<[^<]+?>', b'', m)
 
48
    t = re.compile(b'[0-9]+[0-9]')
50
49
    h = t.search(s).group(0)
51
50
    s = int(h) + 1
52
51
    lista = []
59
58
def get_list_pages():
60
59
    """Get list of pages."""
61
60
    logger.info("Getting list of pages")
62
 
    response = urllib2.urlopen(PAGE_URL)
 
61
    response = request.urlopen(PAGE_URL)
63
62
    html = response.read()
64
63
    lista = scrap_list_page(html)
65
64
    logger.info("    got %d", len(lista))
70
69
    """Scrap the page."""
71
70
    contents = []
72
71
    sanitized = helpers.sanitize(html)
73
 
    soup = BeautifulSoup(sanitized)
 
72
    soup = BeautifulSoup(sanitized, "html.parser")
74
73
    for i in soup.findAll("div", {"class": "video_muestra_catalogo"}):
75
74
        for a_node in i.find_all("a"):
76
75
            onclick = a_node.get("onclick", "")
99
98
def get_content(page_url):
100
99
    """Get content from a page."""
101
100
    logger.info("Getting info for page %r", page_url)
102
 
    u = urllib2.urlopen(page_url)
 
101
    u = request.urlopen(page_url)
103
102
    html = u.read()
104
103
    contents = scrap_page(html)
105
104
    logger.info("    got %d contents", len(contents))