I was just getting started with Instaloader but when i tried to download a specific post, my code wouldn't continue
from instaloader import Instaloader, Profile, Post
# Get instance
L = Instaloader()
L.login(username, password)
print("login complete")
post = Post.from_shortcode(L.context, "CEPH-B0M8B9")
L.download_post(post, target='test')
print("test")
It wouldn't print the "test"
And I was also having some difficulties changing the filename as which the post would get saved. In the documentation it says:
target (Union[str, Path]) – Target name, i.e. profile name, #hashtag,
:feed; for filename.
but that wasn't helping me at all :/
I appreciate every answer :D
After looking at the source code i found the problem.
The download_post function does a lot of stuff and you can deactivate them with these lines:
L = Instaloader()
L.post_metadata_txt_pattern = ""
L.download_geotags = False
L.save_metadata = False
L.save_metadata_json = False
L.download_comments = False
The issue why the code wouldn't continue was that the function just took forever to download all comments
Hope this will help and safe some time for someone in the future :)
Related
I've downloaded the last version of Instapy, and put it on C:\Users\adriel\AppData\Local\Programs\Python\Python39\Lib\site-packages , but always when I run a simple like_by_tag script or any other like script happen this issue:
inappropriate, user_name, is_video, reason, scope = check_link()
I don't know how can I solve it, didn't find good solutions for this.
Anyone has already solved this error before, It looks that this newer version of InstaPy there are many issues to be fixed?
# session
session = InstaPy(username=userInfo['username'], password=userInfo['password'])
session.login()
# comments
session.set_do_comment(enabled=True, percentage= int(probability))
session.set_comments(comentarios, media='Photo')
# likes
session.set_do_like(enabled=True, percentage=100)
session.like_by_tags([tag], amount=int(total))
Because of instagram source code changes. You have to change the code as below:
File : instapy/like_util.py , Line: 619
media = post_page['items'][0]
is_video = media["is_unified_video"]
user_name = media["user"]["username"]
image_text = media["caption"]["text"]
owner_comments = ""
I'm using instaloader to gather some data about my instagram account.
I wrote a very basic loop to get my followers and it worked great:
# Get instance
import instaloader
L = instaloader.Instaloader()
# Login or load session
L.login("myuser", "mypass") # (login)
#L.load_session_from_file(myaccount)
# Obtain profile metadata
profile = instaloader.Profile.from_username(L.context, "testaccount")
# Print list of followees
follow_list = []
count=0
file = open("output.txt","a+")
for followee in profile.get_followers():
username = followee.username , followee.external_url
file.write(username + "\n")
print(username)
file.close()
I tried it on a random bigger account with ~2000 followers on it, just to see it's performance against my test account which has 10 followers to keep it simple.
and I got the error
Requests within last 10/11/20/22/30/60 minutes grouped by type:
* other: 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 666 seconds, at 09:18.
I saw this in the FAQ and troubleshooting section of instaloader and it seems to suggest that this is more common if you're not logged in, so I started wondering if my login was actually working.
I created a session file with the commandline interface
instaloader -login testuser
which worked and created a session file
dev#cab:~/test2 $ ls -la ~/.config/instaloader/session-testuser
I updated the example code
# Get instance
import instaloader
L = instaloader.Instaloader()
# Login or load session
#L.login("myuser", "mypass") # (login)
L.load_session_from_file(testuser)
# Obtain profile metadata
profile = instaloader.Profile.from_username(L.context, "testaccount")
# Print list of followees
follow_list = []
count=0
file = open("output.txt","a+")
for followee in profile.get_followers():
username = followee.username , followee.external_url
file.write(username + "\n")
print(username)
file.close()
however when I then try the script I get the error
Traceback (most recent call last):
File "gram2.py", line 7, in <module>
L.load_session_from_file(testuser)
NameError: name 'testuser' is not defined
from what I've read, but couldn't be sure on the documentation, but did fine examples online I don't need to specify the path to the session file, just the username, and it should automatically look in $user/.conf/instaloader for the session file, so I'm not sure why the session file isn't working, but this then makes me think more that my initial concern that login isn't working is true.
how do I debug / confirm the login is working?
The error refers to L.load_session_from_file(testuser), you have to pass the username as string,so try L.load_session_from_file("testuser")
You need to define testuser as you have passed it as a variable, to fix it pack it inside : "testuser".
Hope that fix your problem.
def convert_to_word():
target = pwd + "/open.doc"
source = pwd + "/template.html"
pythoncom.CoInitialize()
app = win32com.client.Dispatch("Word.Application")
pythoncom.CoInitialize()
# try:
app.Documents.Open(source)
app.Documents.SaveAs2(target,FileFormat=0)
app.Documents.Open(source)
app.Selection.WholeStory()
app.Selection.Fields.Unlink()
app.Documents.Save()
# except Exception as e:
# print(e)
# finally:
app.ActiveDocument.Close()
I need to save html file to .doc, but it report a error <unknown>.SaveAs2 which I cant solve.
Can anyone help me ? Thanks
My first answer on stackoverflow ...
I had had same troubles then I have found solution:
Your code seems to be almost OK. You just need to store your opened document to a variable and then use SaveAs2 function on the variable.
my_doc = app.Documents.Open(source)
my_doc.SaveAs2(target, FileFormat=0)
I am new to Instaloader and I am running into a problem when trying to pull in Bio information. We have scraped Google for a list of Instagram handles for our accounts, unfortunately the data isn't perfect and some of the handles we have pulled in are no longer active(User has changed profile handle or deleted account). This causes the ProfileNotExistsException error to come up and stops pulling in the information for all subsequent accounts.
Is there a way to ignore this and continue pulling in the rest of the bios while just leaving this one blank?
Here is the code that is throwing me the error. handles is the list of handles we have.
bios = []
for element in handles:
if element == '': bios.append('NULL')
else:
bios.append(instaloader.Profile.from_username(L.context, element).biography)
I have tried using the workaround found in this forum(can't find the post) but it is not working for me. No errors, just not solving the issue. The code they suggested was:
def _obtain_metadata(self):
try:
if self._rhx_gis == None:
metadata = self._context.get_json('{}/'.format(self.username), params={})
self._node = metadata['entry_data']['ProfilePage'][0]['graphql']['user']
self._rhx_gis = metadata['rhx_gis']
metadata = self._context.get_json('{}/'.format(self.username), params={})
self._node = metadata['entry_data']['ProfilePage'][0]['graphql']['user']
except (QueryReturnedNotFoundException, KeyError) as err:
raise ProfileNotExistsException('Profile {} does not exist.'.format(self.username)) from err
Thanks in advance!
i need to repeat a cmd which always generated a new random string, after that i need to make sure that this specific string has not been generated before. I never did while loops before and im not able to figure out how to repate the cmd until a result has been found which is not already part of the database. I can't be to specific as this source is closed
all this is packed into a celery task
tasks.py
#app.task
def allocate_new_string(user_pk):
user = User.objects.get(pk=user_pk)
new_string = subprocess.Popen("$get_new_string_cmd", shell=True, stdout=subprocess.PIPE).communicate()[
0].decode('utf-8').strip()
try:
while True:
if Used_String.objects.filter(string=new_string, atom=0).exists():
new_string << how to repeat the command from above here until a new random string has been found?
else:
used_string = Used_String.objects.create(user=user, string=new_string, atom=0)
used_string.save()
logger.info(str("New String has been set)
except:
logger.info(str("Something went wrong while processing the task"))
The function i want to have here is: Search for a none existing sting until one has found that has never been generated before or is at least not part of the database.
the cmd im using isn't openSSL or something like that and it's quite likly that i hit two times the same random generated string.
Thanks in advance
Slight change.
#app.task
def allocate_new_string(user_pk):
user = User.objects.get(pk=user_pk)
try:
Found = True
while Found:
new_string = subprocess.Popen("$get_new_string_cmd", shell=True, stdout=subprocess.PIPE).communicate()[
0].decode('utf-8').strip()
if Used_String.objects.filter(string=new_string, atom=0).exists():
Found = True
else:
used_string = Used_String.objects.create(user=user, string=new_string, atom=0)
used_string.save()
logger.info(str("New String has been set"))
Found = False
except:
logger.info(str("Something went wrong while processing the task"))
I have not tested it but should work. Please try it out and let me know.