
Ayuda con python, expresiones regulares y urllib
Publicado por Madoko (11 intervenciones) el 01/12/2015 18:47:44
Estoy con un curso y me piden que extraiga los numeros que aparecen en un texto
Estoy intentando usar las expresiones regulares, pero no entiendo cual es el problema.
Este es el problema que me da
Traceback (most recent call last):
File "D:\COURSERA PYTHON\EJERCICIOS\prueba130.py", line 14, in <module>
for n in re.findall("\d+",text):
File "C:\Python27\lib\re.py", line 181, in findall
return _compile(pattern, flags).findall(string)
TypeError: expected string or buffer
Imagino que habrá otras formas de hacerlo, por desgracia llevo poco con python y uso lo que voy aprendiendo
Muchas gracias
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import urllib
from BeautifulSoup import *
import re
html=urllib.urlopen("http://python-data.dr-chuck.net/comments_42.html").read()
soup=BeautifulSoup(html)
tags=soup("tr")
text=list()
n=list()
for tag in tags:
text.append(tag)
print text
n= re.findall(\d+,text):
print n
Estoy intentando usar las expresiones regulares, pero no entiendo cual es el problema.
Este es el problema que me da
Traceback (most recent call last):
File "D:\COURSERA PYTHON\EJERCICIOS\prueba130.py", line 14, in <module>
for n in re.findall("\d+",text):
File "C:\Python27\lib\re.py", line 181, in findall
return _compile(pattern, flags).findall(string)
TypeError: expected string or buffer
Imagino que habrá otras formas de hacerlo, por desgracia llevo poco con python y uso lo que voy aprendiendo
Muchas gracias
Valora esta pregunta


0