-1

I'm trying to make a basic program to check if a link is a grabify link by comparing it to available grabify domains, I have a text file that contains all the possible domains and I want to check if a user input is the same.

Q1 = input("input your website domain: ")
PGD = open('Domains', 'r')

if PGD == Q1:
    print("True")

if i input the EXACT domain as one of the lines in my text file it doesn't return anything.

Alomoria
  • 1
  • 1

2 Answers2

0

open() returns a file instance, so you can't compare it directly to a string ; You need to read the file first. You can use the in keyword to search if the string exists in an other string.

Don't forget to close the file at the end.

Q1 = input("input your website domain: ")
PGD = open('Domains', 'r')

if Q1 in PGD.read():
    print("True")

PGD.close()

See also : How to search for a string in text files?

Kusefiru
  • 130
  • 7
0

I think you'll need to read the file first, extract the string and remove any newlines that might be there. Also try to use with open to not have to worry about closing the file again

Q1 = input("input your website domain: ")

with open('Domains') as fopen:
    
    if fopen.read().strip() == Q1:
        print("True")

This assumes you've only got one line in the file. If you had multiple lines to check against:

Q1 = input("input your website domain: ")

with open('Domains') as fopen:
    for line in fopen.readlines():
        if line.strip() == Q1:
        print("True")
Aegir
  • 117
  • 11