Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

185
Visualizações
Extract media files from cache using Selenium

I'm trying to download some videos from a website using Selenium.

Unfortunately I can't download it from source cause the video is stored in a directory with restricted access, trying to retrieve them using urllib, requests or ffmpeg returns a 403 Forbidden error, even after injecting my user data to the website.

I was thinking of playing the video in its entirety and store the media file from cache.

Would it be a possibility? Where can I find the cache folder in a custom profile? How do I discriminate among files in cache?

EDIT: This is what I attempted to do using requests

import requests


def main():

    s = requests.Session()

    login_page = '<<login_page>>'
    login_data = dict()
    login_data['username'] = '<<username>>'
    login_data['password'] = '<<psw>>'

    login_r = s.post(login_page)

    video_src = '<<video_src>>'

    cookies = dict(login_r.cookies) # contains the session cookie

    # static cookies for every session
    cookies['_fbp'] = 'fb.1.1630500067415.734723547'
    cookies['_ga'] = 'GA1.2.823223936.1630500067'
    cookies['_gat'] = '1'
    cookies['_gid'] = 'GA1.2.1293544716.1631011551'
    cookies['user'] = '66051'

    video_r = s.get(video_src, cookies=cookies)
    print(video_r.status_code)



if __name__ == '__main__':
    main()

The print() function returns:

403

This is the network tab for the video:

enter image description here

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Regarding video_r = s.get(video_src, cookies=cookies) Have you try to stream the response ? which send correct byte-range headers to download the video. Most websites prevent downloading the file as "one" block.

with open('...', 'wb') as f:
     response = s.get(url=link, stream=True)
            
     for chunk in response.iter_content(chunk_size=512):
         if chunk:  # filter out keep-alive new chunks
             f.write(chunk)

You can send a head request before if you want, in that way you can create a progress bar, you will retrieve the full content length from header.

Also a 403 is commonly use by anti-bot system, may be your selenium is detected.

over 4 years ago · Santiago Trujillo Relatório

0

You blocked because you forgot about headers. You must use:

s.get('https://httpbin.org / headers', headers ={'user-agent': <The user agent value (for example: last line of your uploaded image)>})

or:

s.headers.update({'user-agent': <The user agent value (for example: last line of your uploaded image)>})

before sending a request

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda