Below I have the following code which opens the correct URL after opening an incorrect one. I know that the link is not getting generated twice because of the print(link) output. So one link is somehow opening two tabs on my browser and I have no idea why. Any thoughts would be appreciated!
I am running python 3.6 on windows 10.
from PIL import Image, ImageEnhance, ImageFilter
import pyscreenshot as ImageGrab
import pytesseract
import webbrowser
import urllib
# I have other code in the middle that is not important
query = textQ
query_encoded = urllib.parse.quote_plus(query)
link = 'http://google.com/search?q='+ query_encoded
print(link)
webbrowser.open_new_tab(link)
EDIT 1 why does this code below open two tabs?
from PIL import Image, ImageEnhance, ImageFilter
import pyscreenshot as ImageGrab
import pytesseract
import webbrowser
import urllib
pytesseract.pytesseract.tesseract_cmd = 'C:/Program Files (x86)/Tesseract-
OCR/tesseract'
if __name__ == "__main__":
# part of the screen
img=ImageGrab.grab()
img.save('screenshot.png')
#-#
query = "textQ"
query_encoded = urllib.parse.quote_plus(query)
link = 'http://google.com/search?q='+ query_encoded
print(link)
webbrowser.open_new_tab(link)