简体   繁体   English

从文件中读取文本并使用 python 附加到 selenium 中的链接

[英]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 “str”对象不可调用

You need to concatenate the string first and then send it to browser.get()您需要先连接字符串,然后将其发送到 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.我相信您的 txt 文件包含一些 Instagram 用户名。 correct me if I am wrong.如果我错了,请纠正我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM