1

I want to write a python script that will ask for reddit post url, go to the page, login with a specified account and upvote the post and the logout.

A) can this be done with python?

B) How would I do this? If you can provide code that would be great, but don't kill yourself.

Mathew Thompson
  • 55,877
  • 15
  • 127
  • 148

2 Answers2

2

Do you really need to interact with JavaScript?

You can reverse engineer Reddit code by looking at AJAX requests made using Firebug or any other debugger, checking cookies, request parameters, etc.

After this you can simulate this requests using Python's urllib by setting same request type (GET vs POST), request parameters and cookies.

Also check this post web-scraping-with-python

Community
  • 1
  • 1
Maksym Kozlenko
  • 10,273
  • 2
  • 66
  • 55
1

Besides @Maksym's great suggestion above, you could also use a browser testing tool like Selenium (which has python bindings) to write a script to interact with the Reddit page directly. The downside is that it would open a copy of your browser every time it runs, and I'm not sure if that would be an issue for you.

mpdaugherty
  • 1,118
  • 8
  • 19
  • If you go this route, I *HIGHLY* suggest splinter: http://splinter.cobrateam.info/ – Mike Axiak Apr 24 '12 at 00:37
  • Thanks to Mike for mentioning splinter. I've used Selenium, windmill (http://www.getwindmill.com/) and this one also looks promising. – Maksym Kozlenko Apr 24 '12 at 01:54
  • Besides that, you can inject custom JavaScript into web page using greasemonkey - https://addons.mozilla.org/en-US/firefox/addon/greasemonkey/ Selenium is primary a JavaScript testing tool and has more overhead compared to GreaseMonkey – Maksym Kozlenko Apr 24 '12 at 01:57