0

I have the following code which will import a .txt file with a list of urls that, with the for statement, I'd like open one by one. Unfortunately webbrowser won't open the link by one by one, but it would open a new Chrome tab with the url "https://link" hence giving me a "about:blank" tab. Do you guys have any idea how to make it work?Thank you very much!

import webbrowser as wb
chrome="/Users/jamesnorton/applications %s"
file=open('File.txt')
for link in file:
    wb.get("google").open_new('link')

1 Answer 1

-2

You are passing a string as parameter not a variable.

Try this instead:

import webbrowser as wb
chrome="/Users/jamesnorton/applications %s"
file=open(file='File.txt',mode='r')
links = file.read()
lines = links.splitlines()
for link in lines:
    wb.get("google").open_new(link)
Sign up to request clarification or add additional context in comments.

2 Comments

Tell me if problem is not solved
That will not solve the problem due in part to a syntax error. Strings are variables albeit immutable

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.