Search code examples
pythonseleniumfopen

Reading text from file and attaching to link in selenium with python


I am trying to read text lines from a file and attach them to the end of a link and perform few actions then read next line and repeat same procedure.

This is what I have so far and appreciate any and all help!

url = "https://www.instagram.com/"
f = open("names.txt")
text1 = [text.strip() for text in f.readlines()]
for text in text1:
    browser.get(url(text1))
    print(url)
f.close

error I am receiving -

'str' object is not callable


Solution

  • You need to concatenate the string first and then send it to browser.get()

    Can you please check this code

    url = "https://www.instagram.com/"
    f = open("names.txt")
    text1 = f.readlines()
    for text in text1:
        driver.get('{}{}'.format(url, text.strip()))
        print('{}{}'.format(url, text.strip()))
    f.close()
    

    I believe your txt file contains some Instagram usernames. correct me if I am wrong.