Skip to content

Instantly share code, notes, and snippets.

@pmarkun
Created July 20, 2013 01:30
Show Gist options
  • Select an option

  • Save pmarkun/6043457 to your computer and use it in GitHub Desktop.

Select an option

Save pmarkun/6043457 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
from lxml.html import parse
import re
arquivo = open('Playboyentrevistas2001.html')
soup = parse(arquivo).getroot()
nome = re.compile(r'([A-Z]*)')
perguntas = soup.xpath("//p[starts-with(text(),'PLAYBOY')]")
raw = []
for p in perguntas:
pergunta = p.text_content()
resposta = p.getnext().getnext().text_content()
autor = re.search(nome, resposta).group()
raw.append('"'+pergunta+'";"'+resposta+'";"'+autor+'"')
zing = open('2001.csv', 'w')
zing.write('\n'.join(raw).encode('utf-8'))
zing.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment