marclave / InstaBot

A simple Instagram bot written in Python
199 stars 74 forks source link

Login is not working #3

Closed kylepierce closed 9 years ago

kylepierce commented 9 years ago

File "instabot.py", line 111, in login(br, profile) File "instabot.py", line 15, in login form = list(br.forms())[0] # Used because the form name was not named
IndexError: list index out of range

This happened after running the script for awhile, so it could be a ban. However, I can access everything fine.

Tried fixing it myself, but .forms() cant find a form because the form is in an iframe.

marclave commented 9 years ago

Hi Kyle,

I am experiencing this as well, i am looking into it immedietly. Thank you for your patience.

marclave commented 9 years ago

Hi Kyle, looks like instagram changed their login page... I will keep investigating

Chizenbop commented 9 years ago

I am experiencing it as well :(

marclave commented 9 years ago

Still looking into it, im trying workarounds.

kylepierce commented 9 years ago

I played around with a few things but I am not very experience in both python or mechanize. Maybe use lxml to find the right spot then use mechanize to fill it in?

marclave commented 9 years ago

I have been playing with the lxml library but still cant get it.

kylepierce commented 9 years ago

My guess is that it cant find the form because the webpage uses javascript to load an iframe. Mechanize doesnt really support javascript this is what they offer in the documentation.

If you come across this in a page you want to automate, you have four options. Here they are, roughly in order of simplicity. Figure out what the JavaScript is doing and emulate it in your Python code: for example, by manually adding cookies to your CookieJar instance, calling methods on HTMLForms, calling urlopen, etc. See above re forms.

Use Java’s HtmlUnit or HttpUnit from Jython, since they know some JavaScript.

Instead of using mechanize, automate a browser instead. For example use MS Internet Explorer via its COM automation interfaces, using the Python for Windows extensions, aka pywin32, aka win32all (e.g. simple function, pamie; pywin32 chapter from the O’Reilly book) or ctypes (example). This kind of thing may also come in useful on Windows for cases where the automation API is lacking. For Firefox, there is PyXPCOM.

Get ambitious and automatically delegate the work to an appropriate interpreter (Mozilla’s JavaScript interpreter, for instance). This is what HtmlUnit and httpunit do. I did a spike along these lines some years ago, but I think it would (still) be quite a lot of work to do well.

marclave commented 9 years ago

Yes you are correct, sadly i cant emulate the js with the current script, i will continue looking into solutions. Anyone else have solutions?

kylepierce commented 9 years ago

As I mentioned in the email I sent you I am just learning python. I was going to try to take a crack at writing the script with selenium. I was excited to see your script work with mechanize because it does all the actions without pretending to be a real browser. Selenium should work very well but it requires a browser to open.

marclave commented 9 years ago

ive been looking at different libraries for a better way, but its not looking good, i think i know what im going to do though... Solution by end of week is the goal

kylepierce commented 9 years ago

Wrote a semi script in selenium. Still having problems with the login but its an open browser so you can just enter them in.

Working on making multi actions since the websta shows them in list format. Like function (xpath) Comment function (class name) Scrape the username, tag used, like?, comment? if yes what? >> CSV file to measure effectiveness.

Chizenbop commented 9 years ago

So this is just the instagram login? not the websta?

marclave commented 9 years ago

Just the instagram login thats not working

Chizenbop commented 9 years ago

So is there no way that we can set the data- attributes and then submit through mechanize?

Chizenbop commented 9 years ago

If we can grab the iFrame src from the document.referrer or another method and then reopen a browser with mechanize for that url would the form submission work (granted we change the control field names)?

marclave commented 9 years ago

Hi Everyone, I have found a workaround for the instagram bot in the latest commit: f4523880f93c04066bdb7a7bb5eca3f5ea06087f I also updated the README with the latest commit 5854910d0c2e2e8ad89c82854ff452f6d8de14d6, please follow it to ensure everything works I know its not the same as before, it might not be better I have not tested more than 10 likes but it works. I know Instagram has a rate limit of 5000 requests per day. Please let me know of any issues, for now this is deemed closed :)

fro35i commented 9 years ago

Thanks for making it work again, but now I only can like 30 images in an hour. I get the following error message:

{"meta":{"error_type":"OAuthRateLimitException","code":429,"error_message":"The maximum number of requests per hour has been exceeded. You have made 38 requests of the 30 allowed in the last hour."}}

I tried with another client but the oauth access-token is always the same, that's why I get the message. Does anybody have the same issue? Thanks

marclave commented 9 years ago

Hi fro35i, you appear to be correct. http://developers.instagram.com/post/87743402071/new-tools-and-rate-limits-for-post-endpoints. I think you should be allowed 100 likes per hour though. I will investigate tonight. Please make a new issue