#para la version 3.8.2 de Python, usar este codigo:
import urllib.request
import re
def getPage():
open_file = open(filePath, 'wb')
html_file = urllib.request.urlopen("http://econpy.pythonanywhere.com/ex/001.html")
html_file = html_file.read()
open_file.write(html_file)
open_file.close()
def getTitulo(filePath):
open_file = open('econpy.html', 'r')
regex = '<div title="buyer-name">'
regexEnd = '</div>'
for line in open_file.readlines():
sentence = line.strip('\n')
if regex in sentence:
initialPos = sentence.find(regex)
initialPos = initialPos + len(regex)
finalPos = sentence.find(regexEnd)
print(sentence[initialPos: finalPos])
def getTituloRegex():
html_file = urllib.request.urlopen("http://econpy.pythonanywhere.com/ex/001.html")
html_file = html_file.read()
regex = rb'<div title="buyer-name">(.+?)</div>'
titulo = re.findall( regex, html_file )
for tit in titulo:
print(tit)
if __name__ == '__main__':
filePath = 'econpy.html'
#getPage()
#getTitulo(filePath)
getTituloRegex()
import urllib.request
import re
def getPage():
open_file = open(filePath, 'wb')
html_file = urllib.request.urlopen("http://econpy.pythonanywhere.com/ex/001.html")
html_file = html_file.read()
open_file.write(html_file)
open_file.close()
def getTitulo(filePath):
open_file = open('econpy.html', 'r')
regex = '<div title="buyer-name">'
regexEnd = '</div>'
for line in open_file.readlines():
sentence = line.strip('\n')
if regex in sentence:
initialPos = sentence.find(regex)
initialPos = initialPos + len(regex)
finalPos = sentence.find(regexEnd)
print(sentence[initialPos: finalPos])
def getTituloRegex():
html_file = urllib.request.urlopen("http://econpy.pythonanywhere.com/ex/001.html")
html_file = html_file.read()
regex = rb'<div title="buyer-name">(.+?)</div>'
titulo = re.findall( regex, html_file )
for tit in titulo:
print(tit)
if __name__ == '__main__':
filePath = 'econpy.html'
#getPage()
#getTitulo(filePath)
getTituloRegex()