Skip to content

Commit 50dc1c1

Browse files
committed
restructured layout and removed driver configuration
1 parent ccf0f8e commit 50dc1c1

File tree

6 files changed

+59
-127
lines changed

6 files changed

+59
-127
lines changed

browsing/endless-scroll.py renamed to browsing/endless_twitter.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
from . import driver, By, WebDriverWait, Condition, Keys
2-
31
import random
42
import time
53

6-
time.sleep(3)
4+
import selenium
5+
import selenium.webdriver
6+
7+
from selenium.webdriver.firefox.options import Options
8+
from selenium.webdriver.common.keys import Keys
9+
# See: https://selenium-python.readthedocs.io/waits.html#explicit-waits
10+
from selenium.webdriver.common.by import By
11+
from selenium.webdriver.support.ui import WebDriverWait
12+
from selenium.webdriver.support import expected_conditions as Condition
713

814
# List of things to search, when no search results left
915
search_list = ['college', 'san%20diego', 'hiking', 'stocks']
@@ -12,6 +18,26 @@
1218
BASE_URL = 'https://twitter.com'
1319
EXTENSION_URL = '/search?q={search}&src=typed'
1420

21+
22+
# Setup headless browser using Firefox
23+
driver_options = Options()
24+
driver_options.headless = True
25+
26+
# It's important we set height and width arguments otherwise page content won't
27+
# render correctly and we can't do things like scroll the full page height!
28+
#
29+
# Actually, this doesn't do anything for Firefox... see below
30+
driver_options.add_argument('--height 900')
31+
driver_options.add_argument('--width 1600')
32+
33+
driver = selenium.webdriver.Firefox(options=driver_options)
34+
35+
# We can set the height here
36+
driver.set_window_size(height=900, width=1600)
37+
38+
# Set an implicit wait for all elements not immediately found
39+
driver.implicitly_wait(10)
40+
1541
driver.get(BASE_URL + EXTENSION_URL.format(search = 'ucsd'))
1642

1743
# Gets last height of browser to compare with future height

driver.py

Lines changed: 0 additions & 36 deletions
This file was deleted.

streaming/curiositystream.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,39 @@
1-
# Our webdriver is set up in the parent `driver` module.
2-
from . import driver, By, WebDriverWait, Condition, Keys
3-
41
import dotenv
52
import os
63
import random
74
import time
85
import urllib.parse as up
96

7+
import selenium
8+
import selenium.webdriver
9+
10+
from selenium.webdriver.firefox.options import Options
11+
from selenium.webdriver.common.keys import Keys
12+
# See: https://selenium-python.readthedocs.io/waits.html#explicit-waits
13+
from selenium.webdriver.common.by import By
14+
from selenium.webdriver.support.ui import WebDriverWait
15+
from selenium.webdriver.support import expected_conditions as Condition
16+
1017
BASEURL = 'https://curiositystream.com'
1118

12-
# Login to the site
19+
# Setup headless browser using Firefox
20+
driver_options = Options()
21+
driver_options.headless = True
22+
23+
# It's important we set height and width arguments otherwise page content won't
24+
# render correctly and we can't do things like scroll the full page height!
25+
#
26+
# Actually, this doesn't do anything for Firefox... see below
27+
driver_options.add_argument('--height 900')
28+
driver_options.add_argument('--width 1600')
29+
30+
driver = selenium.webdriver.Firefox(options=driver_options)
31+
32+
# We can set the height here
33+
driver.set_window_size(height=900, width=1600)
1334

35+
# Set an implicit wait for all elements not immediately found
36+
driver.implicitly_wait(10)
1437
# To figure out that the url was /login I just looked at the url after clicking
1538
# the link manually.
1639
driver.get(up.urljoin(BASEURL, 'login'))

streaming/attenborough.py renamed to streaming/endless_youtube.py

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
# Driver
2-
# ======
3-
#
4-
# This is the base module that all scripts will import from. Basically, we just
5-
# set up the web driver in here, along with an desired options (e.g. Firefox or,
6-
# Chrome, headless, height and width, etc)
7-
#
81
import selenium
92
import selenium.webdriver
103

@@ -21,7 +14,7 @@
2114

2215
# Setup headless browser using Firefox
2316
driver_options = Options()
24-
driver_options.headless = False
17+
driver_options.headless = True
2518

2619
# It's important we set height and width arguments otherwise page content won't
2720
# render correctly and we can't do things like scroll the full page height!
@@ -36,7 +29,7 @@
3629
driver = selenium.webdriver.Firefox(options=driver_options)
3730

3831
# Installs youtube nonstop firefox extension to succesfully autoplay videos
39-
driver.install_addon(current_path + '/streaming/youtube_nonstop-0.8.2-fx.xpi', temporary=True)
32+
driver.install_addon(current_path + '/../extensions/youtube_nonstop-0.8.2-fx.xpi', temporary=True)
4033

4134
# We can set the height here
4235
driver.set_window_size(height=900, width=1600)
@@ -74,20 +67,6 @@ def ensure_playing():
7467
"document.getElementById('movie_player').nextVideo()"
7568
)
7669

77-
# def click_player():
78-
79-
# player = wait.until(
80-
# Condition.presence_of_element_located((By.ID, 'movie_player'))
81-
# )
82-
83-
# # -1 means no ad. If it's anything else, don't click! It could pull us to
84-
# # a new tab and really mess things up.
85-
# if not is_ad():
86-
# player.click()
87-
# else:
88-
# pass
89-
90-
9170
baseurl = 'https://www.youtube.com/watch?v=DqbOgx_FCbw&list=PL6aq1PBlrtR5D4xslD4VBos7zk0GSTuBb'
9271
driver.get(baseurl)
9372

@@ -100,8 +79,6 @@ def ensure_playing():
10079
while True:
10180

10281
current()
103-
# click_player() # pause
10482
time.sleep(1)
10583
ensure_playing() # play
106-
time.sleep(random.randrange(5,18)*60)
107-
84+
time.sleep(random.randrange(5,18)*60)

streaming/youtube_selenium.py

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)