chris-greening / instascrape

Powerful and flexible Instagram scraping library for Python, providing easy-to-use and expressive tools for accessing data programmatically
https://chris-greening.github.io/instascrape/
MIT License
630 stars 107 forks source link

Unable to download Instagram Videos #62

Closed jacksonw765 closed 3 years ago

jacksonw765 commented 3 years ago

When I run this code.

google_hashtag = Hashtag('https://www.instagram.com/explore/tags/google/')
google_hashtag.scrape()
    for x in google_hashtag.get_recent_posts():
        if x['is_video'] is True:
            x.download('tmp.mp4')
            break 

I get this error. I am testing to try and download a video from instagram. Any assistance would be appreciated. It works fine when downloading images.

File "C:\Users\jacks\AppData\Local\Programs\Python\Python39\lib\site-packages\instascrape\scrapers\post.py", line 84, in download
    resp = requests.get(url, stream=True)
  File "C:\Users\jacks\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\api.py", line 76, in get
    return request('get', url, params=params, **kwargs)
  File "C:\Users\jacks\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Users\jacks\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\sessions.py", line 528, in request
    prep = self.prepare_request(req)
  File "C:\Users\jacks\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\sessions.py", line 456, in prepare_request
    p.prepare(
  File "C:\Users\jacks\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\models.py", line 316, in prepare
    self.prepare_url(url, params)
  File "C:\Users\jacks\AppData\Local\Programs\Python\Python39\lib\site-packages\requests\models.py", line 390, in prepare_url
    raise MissingSchema(error)
requests.exceptions.MissingSchema: Invalid URL 'nan': No schema supplied. Perhaps you meant http://nan?
chris-greening commented 3 years ago

Hello Jackson!

get_recent_posts returns an unscraped Post object so all you have to do is call scrape on x before using the download method. Thanks for pointing this ambiguity out! I will make this exception clearer for future users, your contribution is greatly appreciated :smile:

i.e.

google_hashtag = Hashtag('https://www.instagram.com/explore/tags/google/')
google_hashtag.scrape()
for x in google_hashtag.get_recent_posts():
    x.scrape()        #Call scrape on x before downloading
    if x['is_video'] is True:
        x.download('tmp.mp4')
        break 
jacksonw765 commented 3 years ago

Sorry about that! Thank you for the help. I couldn't find anything mentioned about this in the doc and it worked with photos so I thought I was doing something wrong. Appreciate it.