I am trying to make a bot with the help of chatGPT. I know that ChatGPT is not very good at writing code, but I would like to test it to it's limits and see what it can or can't do.
I have found this website that I use for my job. In the website, I type in some numbers and it tells me if this number is active or not. I want the bot to save this in an excel file and print it in the console such that I don't have to check the excel file every time (at least while I'm testing it).
Right now, the bot searches for some keywords on the website. If it finds them, it should print what I want it to print to the console. For example, if it finds the word "No results found" (in Greek) then it should enter that in the excel beside the corresponding number and print "No" in the console. If it doesn't find it, it should print "yes" and put "Active" in the excel file and so on.
However, the code doesn't seem to work. Could it be because of the greek characters? When I run the bot for test purposes, it just prints "yes" even if the key word is not even in there. I have no idea how to solve this problem and any help would be appreciated.
Here's the code:
# Import necessary modules
import openpyxl
import requests
from lxml import html
import webbrowser
import time
# Open the Excel file and get the active worksheet
wb = openpyxl.load_workbook("numbers.xlsx")
sheet = wb.active
# Loop through the rows of the worksheet
for row in sheet.rows:
# Get the value of the first cell in the row
number = row[0].value
# Construct the URL using the number
url = "https://www.vrisko.gr/afm-etairies/" + str(number)
# Open the URL in the default web browser
webbrowser.open_new_tab(url)
# Send a request to the URL and get the response
response = requests.get(url)
# Parse the response using lxml
tree = html.fromstring(response.text)
# Look for the word "Δε βρέθηκαν αποτελέσματα" in the page
word = tree.xpath('//*[contains(text(), "Δε βρέθηκαν αποτελέσματα")]')
word1 = tree.xpath('//*[contains(text(), "Έχετε υπερβεί το μέγιστο αριθμό αναζητήσεων ΑΦΜ για σήμερα.")]')
# If the word is found, write the HTML element containing the word to the next cell in the row
if word:
sheet.cell(row=row[0].row, column=row[0].column+1).value = "X"
print("no")
elif word1:
print("spam")
else:
# If the word is not found, write an "ΕΝΕΡΓΟ" to the next cell in the row
sheet.cell(row=row[0].row, column=row[0].column+1).value = "ΕΝΕΡΓΟ"
print("yes")
# Wait for 1 minute before continuing to the next column
time.sleep(30)
# Save the changes to the Excel file
wb.save("numbers.xlsx")