Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated some changes for 2024 #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions gettyscrape.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.common.by import By
from bs4 import BeautifulSoup
from urllib import urlretrieve
from urllib.request import urlretrieve
import os
import Tkinter, Tkconstants, tkFileDialog
import tkinter
from tkinter import filedialog
import time

def videoscrape():
Expand Down Expand Up @@ -33,10 +34,12 @@ def videoscrape():
time.sleep(10)
driver.get(url)
print(str(j))
section = container[0].find_element_by_xpath(".//section[@class='image-section']")

section = container[0].find_element_by_xpath(".//section[@class='image-section']")
link = section.find_element_by_xpath(".//a[@class='search-result-asset-link']")
video_url = link.get_attribute("href")
driver.get(video_url)
driver.get(video_url)

while True:
wait = WebDriverWait(driver, 30).until(ec.visibility_of_element_located((By.XPATH, "//video[@autoplay='true']")))
data = driver.execute_script("return document.documentElement.outerHTML")
Expand Down Expand Up @@ -64,33 +67,33 @@ def videoscrape():
while True:
while True:
print("Please select a directory to save your scraped files.")
scrape_directory = tkFileDialog.askdirectory()
scrape_directory = filedialog.askdirectory()
if scrape_directory == None or scrape_directory == "":
print("You must select a directory to save your scraped files.")
continue
break
while True:
searchCount = input("Number of search terms: ")
searchCount = int(input("Number of search terms: "))
if searchCount < 1:
print("You must have at least one search term.")
continue
elif searchCount == 1:
searchTerm = raw_input("Search term: ")
searchTerm = input("Search term: ")
else:
searchTerm = raw_input("Search term 1: ")
searchTerm = input("Search term 1: ")
for i in range (1, searchCount):
searchTermPart = raw_input("Search term " + str(i + 1) + ": ")
searchTermPart = input("Search term " + str(i + 1) + ": ")
searchTerm += "-" + searchTermPart
break
while True:
searchPage = input("Number of pages to scrape: ")
searchPage = int(input("Number of pages to scrape: "))
if searchPage < 1:
print("You must have scrape at least one page.")
continue
break
videoscrape()
print("Scraping complete.")
restartScrape = raw_input("Keep scraping? ('y' for yes or 'n' for no) ")
restartScrape = input("Keep scraping? ('y' for yes or 'n' for no) ")
if restartScrape == "n":
print("Scraping ended.")
break