473,404 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

http proxying python and Mechanize

Hi I am trying to make this code run through a new proxy ip each time it runs (ideally using a .txt list of proxies, I know they have to be http). How would I go about doing that, thanks! (also I am willing to buy actual http proxies in order for this to work if thats what I have to do. I just want to the code to work, so far it hasn't).

running vista, python 2.7 and mechanize

Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/python
  2.  
  3. import mechanize
  4. import time
  5. c = chr(124)
  6. ref = "http://kdice.com/r?id=45079336"
  7. USE_PROXY = False
  8. USE_SCARAB = False
  9. br = mechanize.Browser()
  10.  
  11. kevent = "http://kdice.com:80/gwt/EventService"
  12. kgame = "http://kdice.com:80/gwt/GameService"
  13.  
  14. gwtevent   = "5" + c+"0"+c+"4"+c+"http://kdice.com/gwt/"+c+"709ECEA46C2A1C2E2A6E201A883C7074"+c+"org.iogc.client.EventService"+c+"getEvents"+c+"1"+c+"2"+c+"3"+c+"4"+c+"0"+c
  15. gwtservice = "5"+c+"0"+c+"7"+c+"http://kdice.com/gwt/"+c+"1A671DB120885A115DE783B967FE5EB2"+c+"org.iogc.kdice.client.KGameService"+c+"startSession"+c+"I"+c+"java.lang.String"+c+"paypal"+c+"1"+c+"2"+c+"3"+c+"4"+c+"2"+c+"5"+c+"6"+c+"3"+c+"7"+c
  16. gwtleave   = "5"+c+"0"+c+"4"+c+"http://kdice.com/gwt/"+c+"1A671DB120885A115DE783B967FE5EB2"+c+"org.iogc.kdice.client.KGameService"+c+"leave"+c+""+c+"1"+c+"2"+c+"3"+c+"4"+c+"0"
  17.  
  18. from mechanize import Browser,Request,urlopen,CookieJar,RobustFactory
  19. import cookielib
  20.  
  21. f = open('C:\\twitter.txt')
  22. twitterlist = f.readlines()
  23.  
  24. if USE_PROXY:
  25.     f = open('C:\\proxies.txt')
  26.     proxylist = f.readlines()
  27.  
  28. if USE_SCARAB:
  29.   br.set_proxies({"http":"localhost:8008"})
  30. elif USE_PROXY:
  31.   br.set_proxies({"http":proxylist})
  32.  
  33. for twit in twitterlist:
  34.   cj = CookieJar()
  35.   br.set_cookiejar(cj)
  36.   br.set_handle_robots(False)
  37.  
  38.   r2 = br.open(ref)
  39.  
  40.   br.addheaders = [('User-Agent', 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.100 Safari/534.30')]
  41.   res = br.open(kgame,str(gwtservice))
  42.  
  43.   br.addheaders = [('Content-Type',  "text/x-gwt-rpc; charset=UTF-8")]
  44. #  br.addheaders = [('User-Agent', 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.100 Safari/534.30')]
  45.   br.addheaders = [('Referer',kgame)]
  46.   r = br.open(kevent,gwtevent)
  47.  
  48. #5|0|7|http://kdice.com/gwt/|1A671DB120885A115DE783B967FE5EB2|org.iogc.kdice.client.KGameService|startSession|I|java.lang.String|nodice4u|1|2|3|4|2|5|6|3|7|
  49.  
  50. #twitter oath working fine
  51.   namepass = twit.split("|")
  52.   r = br.open("http://kdice.com:80/twitterOauth")
  53.   print namepass[0],namepass[1]
  54.   br.select_form(nr=0)
  55.   print br.viewing_html()
  56.   br.form["session[username_or_email]"] = namepass[0]
  57.   br.form["session[password]"] = namepass[1][:-1]
  58.   br.submit()
  59. #r = br.open(kevent,gwtmain+gwtevent)
  60. #  print r.read()
  61.   print br.response().read()
  62.   res = br.open(kgame,str(gwtservice))
  63.   print res.read()
  64.  

ideally I'd like for it to select the following proxy from a .txt file and use that to connect via mechanize as it uses login information from a .txt file. My understanding of mechanize sort of breaks down when it comes to proxies so I'm in real quandary here, any help would be much obliged.

If you want to try running the script yourself feel free to use this twitter logins in a .txt file.

elffirezd|3n99yvyb7f
forgottea|993fatb2j4
hinatamuc|bay9b64ngf
tabibitob|x76q17m228
antillesa|47mnj37911

The reason it must work with proxies has to do with the referral system we're currently testing and debugging. Thank you.

Oh and if necessary I can probably provide some http proxies too.

edit: Right now it runs perfectly without proxies but of course the referral only works once. so we want to test it out the referral system multiple times by using proxy IPs
Aug 31 '11 #1
0 1656

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Wenning Qiu | last post by:
I am researching issues related to emdedding Python in C++ for a project. My project will be running on an SMP box and requires scalability. However, my test shows that Python threading has very...
6
by: test | last post by:
Hi everyone, I'm creating a desktop Python application that requires web-based authentication for accessing additional application features. HTTP GET is really simple. HTTP POST is not (at...
1
by: bruce | last post by:
hi.. i'm trying to figure out how to uninstall "mechanize". i don't see an "unistall" from the "python --help-commands" function... i'm looking to rebuild/reinstall mechanize from the svn...
0
by: bruce | last post by:
i'm getting the following error: mechanize._response.httperror_seek_wrapper: HTTP Error 500: i'm running python 5.1 and mechanize 0.1.7b I have no idea as to what I have to...
1
by: bruce | last post by:
hi... i've got the following situation, with the following test url: "http://schedule.psu.edu/soc/fall/Alloz/a-c/acctg.html#". i can generate a list of the tables i want for the courses on the...
1
by: bruce | last post by:
evening... using mechanize/Browser, i can easily do a url/get, and process submitting a form that uses a GET as the action. however, I'm not quite sure how to implement the submittal of a form,...
0
by: Mohamed Yousef | last post by:
Hello , i don't know about mechanize but in general all you have to do is a simple socket text sending connect to the server then send it POST headers to page in question.. what to send ?...
0
by: John J Lee | last post by:
On Mon, 1 Sep 2008, bruce wrote: Just a general point: try lxml.etree instead? Friendlier API. John
0
by: John J Lee | last post by:
On Tue, 2 Sep 2008, bruce wrote: Same way as any other form. The HTTP method used is determined by the value of the form element's "action" attribute.
1
by: tedpottel | last post by:
Hi, I can read the home page using the mechanize lib. Is there a way to load in web pages using filename.html instad of servername/ filename.html. Lots of time the links just have the file...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.