Q:

How convert print in table csv beautiful soup

the problem of my code is not save in the csv archive, create a csv but in blank. Using the print function show the results but not save in csv.
import csv
import urllib2
from bs4 import BeautifulSoup
url = "html"  
page = urllib2.urlopen(url).read()
soup = BeautifulSoup(page)
for tr in soup.find_all('tr')[2:]:
    tds = tr.find_all('h2') 
    td2 = tr.find_all('th')
    hora = tds[0].text.encode('utf-8')
    nombre = td2[0].text.encode('utf-8')
    print hora, nombre
    f = csv.writer(open("prueba.csv", "w"))
    f.writerow(["Hora", "Nombre"])
    f.writerow([hora, nombre])

A:

The csv file that I get is:

Hora,Nombre
" Alaska y Segura ", 23:50
23:15

The reason is that you open the file in w mode every time you want to write to it. w mode replaces the content of a file if it already exists - it truncates the file, it does not append to the file. To append you should use a instead:
f = csv.writer(open("prueba.csv", "a"))

Another option, which is better since there is no need to close the file and reopen it again and again, is to only open the file once:
import csv
import urllib2
from bs4 import BeautifulSoup
url = r"http://laguiatv.abc.es/programacion/tve-1-807.html"  
page = urllib2.urlopen(url).read()
soup = BeautifulSoup(page)
f = csv.writer(open("prueba.csv", "w"))
for tr in soup.find_all('tr')[2:]:
    tds = tr.find_all('h2') 
    td2 = tr.find_all('th')
    hora = tds[0].text.encode('utf-8')
    nombre = td2[0].text.encode('utf-8')
    print hora, nombre
    f.writerow(["Hora", "Nombre"])
    f.writerow([hora, nombre])

See the documentation for the open function:

'w' for writing (truncating the file if it already exists), and 'a' for appending

