用Python制作Instagram下载器[已关闭]

13z8s7eq  于 2023-01-16  发布在  Python
关注(0)|答案(2)|浏览(196)

已关闭。此问题需要details or clarity。当前不接受答案。
**想要改进此问题?**添加详细信息并通过editing this post阐明问题。

昨天关门了。
Improve this question
帮助我能够正确地下载Instagram与Python(帖子,故事,个人资料)
我没有尝试过任何Python库

4dbbbstv

4dbbbstv1#

试试这个:

#importing the libraries
import requests
from instaloader import Instaloader

#enter the username
username = input("Enter the username: ")

#create an instance of Instaloader
L = Instaloader()

#Log in or authenticate
L.login('username', 'password')

#get the profile
profile = instaloader.Profile.from_username(L.context, username)

#download the posts
posts = profile.get_posts()
for post in posts:
    L.download_post(post, target=username)

#download the stories
stories = profile.get_stories()
for story in stories:
    L.download_storyitem(story, profile.username)

或者这个图像:

import requests
from bs4 import BeautifulSoup

username = input("Enter the username of the Instagram user: ")

url = f"https://www.instagram.com/{username}/"

req = requests.get(url)
soup = BeautifulSoup(req.text, 'html.parser')

posts = soup.findAll('div', class_="v1Nh3 kIKUG  _bz0w")

for post in posts:
    img_src = post.find('img')['src']
    img_name = img_src.split('/')[-1]
    img_data = requests.get(img_src).content
    with open(img_name, 'wb') as handler:
        handler.write(img_data)
    print(f"{img_name} downloaded")
ycl3bljg

ycl3bljg2#

from urllib.request import open as op
with open('file path' ,'wb') as file:
    file.write(op('your link').read()))

相关问题