Click here to Skip to main content
15,847,653 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i have this code
 `import re
file = "/home/user/Desktop/ricerca-segnali-operativi"
try:
    with open(file, "r") as f:
        content = f.read()
except FileNotFoundError:
    print(f"The file {file} was not found.")
    exit()

start = "Data candela segnale Crypto Tipo Prezzo ingresso"
end = "* Privacy Policy"
#result = re.findall(f'{start}(.*?){end}', content, re.DOTALL)
result = re.findall(f'.*{start}.*?(.*?){end}.*', content, re.DOTALL)

if not result:
    print(f"No content found between '{start}' and '{end}'")
    exit()

result = [i.strip() for i in result[0].split('\n') if i]

final_result = []
for i in result:
    data = i.split()
    final_result.append(data)

print(final_result)

i want with this code take a line between this two line,first line is,"Data candela segnale Crypto Tipo Prezzo ingresso" and last line is "* Privacy Policy" in the middle i have this and i want take it
2023-02-04 HIVEBTC Buy 0.000025
2023-02-04 HIVEUSDT Buy 0.571

this my example of txt
Notice: Undefined index: HTTP_USER_AGENT in /var/www/clients/client1/web6/web/config.php on line 10
Segnali daily

   Data candela segnale  Crypto  Tipo Prezzo ingresso
        2023-02-04      HIVEBTC  Buy  0.000025
        2023-02-04      HIVEUSDT Buy  0.571

     * Privacy Policy
     * Cookie Policy


What I have tried:

i tryed also this:
result = re.findall(f'{start}(.*?){end}', content, re.DOTALL)

but return always to No content found between 'Data candela segnale Crypto Tipo Prezzo ingresso' and '* Privacy Policy'
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900