1
I’m having trouble importing the function of a module and making use of it.
I already made sure to put the file __init__.py
folder. But I can’t make use of the functions.
The program will download the HTML content from a web page, and cut out substrings (initial and final subs search) and cut between them. Also makes a follow-up offser of each tag’s initial and final position.
My program (already with the functions of the module, but I need to remove them). I left to test the functionality.
# -*- coding: utf-8 -*-
import requests
Texto = requests.get('https://www.panvel.com/panvel/concor-hct-5mg125mg-30-comprimidos/p-622540')
#print("Status Code :", Texto.status_code)
#print(Texto.headers)
def PosEx(Substring,Texto,Offset):# Retorna resultado de corte em textos com offset e upper ignore
return Texto.find(Substring,Offset)
Offset = 0
def CortaFora(Offset,Texto,Inicio,Fim): # Da o que está entre o inicio e o fim em determinado texto, respeitando offset e retornando offset inclusive.
Inicial = Final = ''
Inicial = PosEx(Inicio,Texto,Offset)+len(Inicio)
# print('Pos Inicial:'+str(Inicial))
Offset = Inicial
Final = PosEx(Fim,Texto,Offset)
# print('Pos Final:'+str(Final))
Offset = Final
return Texto[Inicial:Final].strip(' '), Offset
a = Texto.text
b = PosEx('<h1 class="item-title">',a, Offset)
print('Posição antes do corta Fora do Offset:' +str(b))
print('')
d,Offset = CortaFora(Offset, a,'<h1 class="item-title">','</h1>')
print(d)
print('')
print('Posicao Após Corta Fora do Offset:'+str(Offset))
Module I want to import the functions PosEx
and CortaFora
:
# -*- coding: utf-8 -*-
def PosEx(Substring,Texto,Offset):# Retorna resultado de corte em textos com offset e upper ignore
# return Texto.find(Substring,Offset)
Offset = 0
def CortaFora(Offset,Texto,Inicio,Fim): # Da o que está entre o inicio e o fim em determinado texto, respeitando offset e retornando offset inclusive.
Inicial = Final = ''
Inicial = PosEx(Inicio,Texto,Offset)+len(Inicio)
# print('Pos Inicial:'+str(Inicial))
Offset = Inicial
Final = PosEx(Fim,Texto,Offset)
# print('Pos Final:'+str(Final))
Offset = Final
return Texto[Inicial:Final].strip(' '), Offset
Thanks Octavian! , it worked, lack of attention and experience, I thought it was necessary to call the function!!
– Marcos Silveira