URL: https://linuxfr.org/users/moules/journaux/browser-2-teaser Title: Browser 2 – Teaser Authors: moules Date: 2014年03月20日T21:01:32+01:00 License: CC By-SA Tags: weboob Score: -28 # Avant ```python class IndexPage(BasePage): def iter_videos(self): span_list = self.parser.select(self.document.getroot(), 'span#miniatura') for span in span_list: a = self.parser.select(span, 'a', 1) url = a.attrib['href'] _id = re.sub(r'/videos/(.+)\.html', r'1円', url) video = YoujizzVideo(_id) video.thumbnail = BaseImage(span.find('.//img').attrib['data-original']) video.thumbnail.url = video.thumbnail.id title_el = self.parser.select(span, 'span#title1', 1) video.title = to_unicode(title_el.text.strip()) time_span = self.parser.select(span, 'span.thumbtime span', 1) time_txt = time_span.text.strip().replace(';', ':') hours, minutes, seconds = 0, 0, 0 if ':' in time_txt: t = time_txt.split(':') t.reverse() seconds = int(t[0]) minutes = int(t[1]) if len(t) == 3: hours = int(t[2]) elif time_txt != 'N/A': raise BrokenPageError('Unable to parse the video duration: %s' % time_txt) video.duration = datetime.timedelta(hours=hours, minutes=minutes, seconds=seconds) yield video ``` # Après ```python class IndexPage(HTMLPage): @method class iter_videos(ListElement): item_xpath = '//span[@id="miniatura"]' next_page = Link(u'//a[text()="Next »"]') class item(ItemElement): klass = BaseVideo obj_id = Regexp(Link('.//a'), r'/videos/(.+)\.html') obj_title = CleanText('.//span[@id="title1"]') obj_duration = Duration(CleanText('.//span[@class="thumbtime"]//span'), default=NotAvailable) obj_nsfw = True def obj_thumbnail(self): thumbnail = BaseImage(Attr('.//img', 'data-original')(self)) thumbnail.url = thumbnail.id return thumbnail ``` [](http://planet.weboob.org/)