instaloader / instaloader

Download pictures (or videos) along with their captions and other metadata from Instagram.
https://instaloader.github.io/
MIT License
8.67k stars 1.18k forks source link

Facing issue while getting profile information using username, previously It was working #2005

Closed iyashjayesh closed 1 year ago

iyashjayesh commented 1 year ago
import instaloader

ACCOUNT_USERNAME=""
ACCOUNT_PASSWORD=""
# Creating an instance of the Instaloader class
bot = instaloader.Instaloader()
bot.login(ACCOUNT_USERNAME, ACCOUNT_PASSWORD)

# list of users > 1000
# this is just for example 
username = "instagram"
profile = instaloader.Profile.from_username(bot.context, username)
print("Trying to scrape profile of:", profile.username)
print("Number of Posts: ", profile.mediacount)
print("Followers Count: ", profile.followers)
print("Following Count: ", profile.followees)

I'm trying to run the above code but facing the bellow issue,

issue:

HTTP redirect from https://i.instagram.com/api/v1/users/web_profile_info/?username=instagram to Number of requests within last 10/11/20/22/30/60 minutes grouped by type:
                              other:    1    1    1    1    1    1
 *                           iphone:    1    1    1    1    1    1
Instagram responded with HTTP error "429 - Too Many Requests". Please
do not run multiple instances of Instaloader in parallel or within
short sequence. Also, do not use any Instagram App while Instaloader
is running.
The request will be retried in 30 minutes, at 18:04.

can anyone please help me to resolve this? After every 30 mins, it's saying the same thing again and again, any resolution?

ihabpalamino commented 1 year ago

you may be connecting with the same account you're scraping with in your phone disconnect from your phone

ihabpalamino commented 1 year ago

you may be connecting with the same account you're scraping with in your phone disconnect from your phone

iyashjayesh commented 1 year ago

you may be connecting with the same account you're scraping with in your phone disconnect from your phone

iyashjayesh commented 1 year ago

you may be connecting with the same account you're scraping with in your phone disconnect from your phone

no I'm not doing that.

ihabpalamino commented 1 year ago

i faced the same problem hen i disconnect from my phone and get cookies and import session file from firefox it works fine after that

iyashjayesh commented 1 year ago

i faced the same problem hen i disconnect from my phone and get cookies and import session file from firefox it works fine after that

how can we do that? can you provide me with any quick steps?

ihabpalamino commented 1 year ago

okey i will provide you my code and do the changes you need to do

def get_cookiefile(): default_cookiefile = { "Windows": "~/AppData/Roaming/Mozilla/Firefox/Profiles//cookies.sqlite", "Darwin": "~/Library/Application Support/Firefox/Profiles//cookies.sqlite", }.get(system(), "~/.mozilla/firefox/*/cookies.sqlite") cookiefiles = glob(expanduser(default_cookiefile)) if not cookiefiles: raise SystemExit("No Firefox cookies.sqlite file found. Use -c COOKIEFILE.") return cookiefiles[0]

def import_session(cookiefile, sessionfile): print("Using cookies from {}.".format(cookiefile)) conn = connect(f"file:{cookiefile}?immutable=1", uri=True) try: cookie_data = conn.execute( "SELECT name, value FROM moz_cookies WHERE baseDomain='instagram.com'" ) except OperationalError: cookie_data = conn.execute( "SELECT name, value FROM moz_cookies WHERE host LIKE '%instagram.com'" ) instaloader = Instaloader(max_connection_attempts=1) instaloader.context._session.cookies.update(cookie_data) username = instaloader.test_login() if not username: raise SystemExit("Not logged in. Are you logged in successfully in Firefox?") print("Imported session cookie for {}.".format(username)) instaloader.context.username = username instaloader.save_session_to_file(sessionfile)

def scrape_instagram(): username = request.form.get('username') since_date = request.form.get('since') until_date = request.form.get('until') PLATFORM_NAME = request.form.get('plateform') if not username: return jsonify({'error': 'Username is required.'}), 400

session_cookiefile = get_cookiefile()
sessionfile = "" //write here the username of the account you're scraping with

import_session(session_cookiefile, sessionfile)  # Import the session cookie

L = instaloader.Instaloader()
L.load_session_from_file(sessionfile)

posts = instaloader.Profile.from_username(L.context, username).get_posts()
SINCE = datetime.strptime(since_date, "%Y-%m-%d")
UNTIL = datetime.strptime(until_date, "%Y-%m-%d")

data = []
for post in takewhile(lambda p: p.date > UNTIL, dropwhile(lambda p: p.date > SINCE, posts)):
    if post.is_video:
        viewVideo = post.video_view_count
    else:
        viewVideo = None

    post_data = {
        "id_post": post.mediaid,
        "Date": post.date.strftime("%Y-%m-%d"),
        "Heure": post.date.strftime("%H:%M:%S"),
        "content": post.caption,
        "username": post.owner_username,
        "likecount": post.likes,
        "viewVideo": viewVideo,
        "comments": post.comments,
        "platformname": PLATFORM_NAME
    }
    data.append(post_data)

df = pd.DataFrame(data, columns=["id_post", "Date", "Heure", "content", "username", "likecount", "viewVideo",
                                 "comments", "platformname"])
csv_path = "C:/Users/HP Probook/OneDrive/Images/Bureau/CsvScraping/instagram.csv"
df.to_csv(csv_path, mode="w", sep=";", encoding='utf-8', index=False)
Infos_json = df.to_json(orient='records', indent=4, force_ascii=False)
clean_insta_json = re.sub(r"[\x00-\x1F\x7F-\x9F]", "",
                          Infos_json)  # Supprimer les caractères de contrôle non valides
response = jsonify(json.loads(clean_insta_json))
response.headers['Content-Type'] = 'application/json'

return response
github-actions[bot] commented 1 year ago

There has been no activity on this question for an extended period of time. This issue will be closed after further 14 days of inactivity.

rashaed44 commented 1 day ago
import instaloader

ACCOUNT_USERNAME=""yf19518
ACCOUNT_PASSWORD=""776926749@o
# Creating an instance of the Instaloader class
bot = instaloader.Instaloader(e163_1169BOT)
bot.login(ACCOUNT_USERNAME, ACCOUNT_PASSWORD)

# list of users > 1000
# this is just for example 
username = "instagram"
profile = instaloader.Profile.from_username(bot.context, username)
print("Trying to scrape profile of:", profile.username)
print("Number of Posts: ", profile.mediacount)
print("Followers Count: ", profile.followers)
print("Following Count: ", profile.followees)

I'm trying to run the above code but facing the bellow issue,

issue:

HTTP redirect from https://i.instagram.com/api/v1/users/web_profile_info/?username=instagram to Number of requests within last 10/11/20/22/30/60 minutes grouped by type:
                              other:    1    1    1    1    1    1
 *                           iphone:    1    1    1    1    1    1
Instagram responded with HTTP error "429 - Too Many Requests". Please
do not run multiple instances of Instaloader in parallel or within
short sequence. Also, do not use any Instagram App while Instaloader
is running.
The request will be retried in 30 minutes, at 18:04.

can anyone please help me to resolve this? After every 30 mins, it's saying the same thing again and again, any resolution?

rashaed44 commented 1 day ago

e163_1169BOT