Created
November 23, 2023 06:11
-
-
Save goodylili/80cecd4166936685c614586563117e03 to your computer and use it in GitHub Desktop.
script that reads articles for views
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import schedule | |
from selenium import webdriver | |
from selenium.webdriver.firefox.options import Options | |
import time | |
import random # Import the random module | |
def setup_tor_profile(): | |
"""Sets up a Firefox profile for Tor.""" | |
profile = webdriver.FirefoxProfile() | |
profile.set_preference('network.proxy.type', 1) | |
profile.set_preference('network.proxy.socks', '127.0.0.1') | |
profile.set_preference('network.proxy.socks_port', 9150) | |
profile.set_preference("network.proxy.socks_remote_dns", False) | |
return profile | |
def initialize_webdriver(profile, tor_path): | |
"""Initializes the WebDriver for Firefox with the given profile and Tor path.""" | |
options = Options() | |
options.binary_location = tor_path | |
options.profile = profile | |
options.add_argument("--headless") # Enable headless mode | |
driver = webdriver.Firefox(options=options) | |
return driver | |
def scroll_page(driver): | |
"""Scrolls through the webpage with randomized speed like a human reader.""" | |
total_height = int(driver.execute_script("return document.body.scrollHeight")) | |
for i in range(0, total_height, 100): | |
driver.execute_script("window.scrollTo(0, {});".format(i)) | |
time.sleep(random.uniform(1, 5)) # Randomize sleep time between 0.05 and 0.30 | |
def launch_tor_with_selenium(url, visit_counter): | |
"""Main function to launch a website using Tor and Selenium.""" | |
tor_path = '../../Applications/Tor Browser.app/Contents/MacOS/firefox' # Update as needed | |
profile = setup_tor_profile() | |
driver = initialize_webdriver(profile, tor_path) | |
driver.get(url) | |
scroll_page(driver) | |
driver.quit() | |
print(f"Visited {url} {visit_counter} times") | |
def run_periodically(): | |
visit_counter = 0 | |
while True: | |
visit_counter += 1 | |
launch_tor_with_selenium('https://semaphoreci.com/blog/debugging-go', visit_counter) | |
time.sleep(1800) # Sleep for 1800 seconds (30 minutes) | |
# Start the periodic execution | |
run_periodically() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment