import pprint import urllib import requests import lxml.html from selenium import webdriver BASE_URL = "https://vimeo.com/search" hdr = { "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Charset": "ISO-8859-1,utf-8;q=0.7,*;q=0.3", "Accept-Encoding": "none", "Accept-Language": "en-US,en;q=0.8", "Connection": "keep-alive", } def parse_vimeo_page(page: str): tree = lxml.html.fromstring(page) items = [] videos = tree.cssselect("a.chakra-card > data-testid[clip-result]") for item in videos: print(item.text_content()) # title = item.xpath('.//div[@class="video-title"]/a/text()')[0] # url = item.xpath('.//div[@class="video-title"]/a/@href')[0] # items.append({ # "title": title, # "url": url # }) return items def search_vimeo(type: str, query: str, price: str, resolution: str): url = f"{BASE_URL}?type={type}&q={query}&price={price}&resolution={resolution}" # req = requests.get(url, headers=hdr) # the_page = req.text # print(the_page) # tree = parse_vimeo_page(the_page) # return tree driver = webdriver.Chrome() driver.get(url) the_page = driver.page_source tree = parse_vimeo_page(the_page) driver.quit() return tree # req = urllib.request.Request(url, headers=hdr) # with urllib.request.urlopen(req) as response: # the_page = response.read() # tree = parse_vimeo_page(the_page) # return tree if __name__ == "__main__": pprint.pprint( search_vimeo(type="clip", query="paramore", price="free", resolution="4k") )