1
import webbrowser
import os
n = ""
while (n == ""):
  n = input("How many pages do you want?\n")
start_page = ""
url = input("Yeezy Supply or Adidas?""\nEither 'YS' or 'Adidas'\n")
url_choice = url.lower()
#print(url_choice)

if url_choice == 'ys':
  start_page = "www.yeezysupply.com/"
elif url_choice == "adidas":
  start_page =  "www.adidas.com/yeezy"
#print(start_page)

page_number = list()
for i in range(0, int(n)):
  page_number.append(n)

for i in range(0, len(page_number)):
  chromelink = r"C:\Users\Michael\Desktop\FlashCop\bin\chromedriver.exe"
  webbrowser.register('chrome',None,webbrowser.BackgroundBrowser(chromelink))
  os.system(r'cmd /c "C:\Users\Michael\Desktop\FlashCop\bin\chromedriver.exe"start_page')
  webbrowser.open_new(start_page)

This only yields in opening new tabs. Is there a way to force chrome to open a new window and not a new tab?

  • Are you expecting an answer different than [last time](https://stackoverflow.com/questions/59382989/how-can-i-use-python-to-open-multiple-windows-and-not-just-multiple-tabs-in-my-c)? – martineau Dec 18 '19 at 02:28
  • @martineau someone said there was a way but that way didnt work so i reposted to get new answers... –  Dec 18 '19 at 02:30

1 Answers1

0

Try this:

import subprocess

chrome_path = "chrome.exe --new-window"

times = ""
start_page = ""

while times == "":
    times = input("How many pages do you want?\n")

url = input("Yeezy Supply or Adidas?""\nEither 'YS' or 'Adidas'\n")
url_choice = url.lower()

if url_choice == 'ys':
    start_page = "www.yeezysupply.com/"
elif url_choice == "adidas":
    start_page = "www.adidas.com/yeezy"

page_number = list()
for i in range(0, int(times)):
    page_number.append(times)


for i in range(0, len(page_number)):
    command = 'cmd /c "%s %s"' % (chrome_path, start_page)
    process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)

It opens the url with cmd (as subprocess) in new window due to --new-window flag.


Make sure to add chrome.exe or chromedriver in path variables - tutorial (pdf) or make sure to add full filepath to the webbrowser executable / binaries you want to use.

JaFizz
  • 328
  • 2
  • 20
  • 1
    when running this i only get this message PS C:\Users\Michael\documents> py FlashCop.py Starting ChromeDriver 79.0.3945.36 (3582db32b33893869b8c1339e8f4d9ed1816f143-refs/branch-heads/3945@{#614}) on port 9515 Only local connections are allowed. Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code. The script doesnt actually run. –  Dec 18 '19 at 02:05
  • Could you try to replace "chrome.exe" to the full path of where your chrome.exe is located! maybe that helps! – JaFizz Dec 18 '19 at 02:07
  • Why do you wan't to open the urls in seperate windows? What is the purpose of opening the urls with chromedriver? – JaFizz Dec 18 '19 at 02:20
  • 1
    Hi sorry i made an error, im not sure where to put this new code. I placed it infront of webbrowser.open_new(start_page) and it still opens up in a tab –  Dec 18 '19 at 02:21
  • 1
    is there an easier way to open multiple windows without using chromedriver or chrome? i need to do it for a project ive been working on –  Dec 18 '19 at 02:22
  • 1
    i edited the code to show the editions, please check it out, this opens the page but only in tabs, it also gives this error chromedriver.exestart_page' is not recognized as an internal or external command, operable program or batch file. –  Dec 18 '19 at 02:25
  • I edited my answer, I hope this works out for you. If you can execute chromedrive.exe with the --new-window flag, that will be a fix also! – JaFizz Dec 18 '19 at 03:12