-4

Ok so my problem is that I wanted to make a "meme" program that would simply open a bunch of p0rn sites in different tabs with videos that would all start playing and my problem is that I can't figure out how to do so with the tabs, because every single URL in my links.json array will just reload on the same tab so in a span of probably 2 seconds all the pages reload on the same tab and I haven't found any fixes for that on the Internet "using an array, a loop and not closing the tabs" otherwise there are some fixes but the program doesn't make sense if you just have to close the tabs almost immediately so I'm asking does any of you know how to somehow do it using the Selenium thing? I know that there are some other ways, but then the program wouldn't make sense it should work somehow like this:

Open program -> Open Chrome -> for link in links: open new tab with the URL in the .json file(array) -> find element with ("YES I am 18 years or older) -> click on the YES button -> find the play button -> click on it and somehow repeat the process for all the URL's or elements in the links.json file

The code that I wrote doesnt have much implemented yet because I just cant figure out how to repeat the loop with the new tabs

The code (so far):

import string
import os
import json
from selenium import webdriver
import webbrowser
from selenium.webdriver.common.keys import Keys
import chromedriver_binary
import time
from selenium.webdriver import ActionChains

driver = webdriver.Chrome(executable_path='C:\Program Files\chromedriver80\chromedriver.exe')
links = json.loads(open("links.json").read())

for link in links:
    driver.get(link) #only opens all the files in one tab :(
    #THIS IS HOW IT SHOULD BE IDEALLY:
    #NEW TAB
    #Open URL in Chrome
    #Find 18y.o. button
    #press YES
    #find play button 
    #press it
    #LOOP AGAIN 
    print("Now accessing: " + link)

The .json file(I am not sure if I can add the actuall links so if you want to test it maybe just find your own I used xnnx just sayin')

[ "p0rnLinkNo.0",
  "p0rnLinkNo.1",
  "p0rnLinkNo.2",
  "p0rnLinkNo.3",
  "p0rnLinkNo.4"]

I can figure out the buttons but can't figure out the tabs please HELP

  • Many examples here on stackoverflow. Do some searching! https://stackoverflow.com/questions/28431765/open-web-in-new-tab-selenium-python#28432939 – Alex R Feb 20 '20 at 20:07
  • 1
    Does this answer your question? [Open web in new tab Selenium + Python](https://stackoverflow.com/questions/28431765/open-web-in-new-tab-selenium-python) – AMC Feb 20 '20 at 20:11
  • Hi, thanks for feedback but I have already seen couple of these and tried it for my self, which didn't work the CONTROL + t solution doesnt work in Chrome 80 – Mr.Programmer Feb 20 '20 at 20:20

1 Answers1

-2

I am sorry for posting I already had the solution but I defined variable in a wrong place so it didn't work solution CODE:

import string
import os
import json
from selenium import webdriver
import webbrowser
from selenium.webdriver.common.keys import Keys
import chromedriver_binary
import time
from selenium.webdriver import ActionChains

driver = webdriver.Chrome(executable_path='C:\Program Files\chromedriver80\chromedriver.exe')
links = json.loads(open("links.json").read())
temp = 1
for link in links:
    driver.execute_script("window.open('');")
    driver.switch_to.window(driver.window_handles[temp])
    driver.get(link)
    print("Now accessing: " + link)
    temp += 1

Thanks for downvotes btw XD