python - Urllib Request only working for one user -
im writing web bot , ive ran problem
basically bot logs in buys , sells shares in game works when put in username , pass when put in differnt 1 error saying ive been directed wrong page though used referer header
here login code:
def login(self): while true: self.cookiejar = cookielib.lwpcookiejar() self.opener = urllib2.build_opener( urllib2.httpcookieprocessor(self.cookiejar), urllib2.httpredirecthandler(), urllib2.httphandler(debuglevel=0)) self.opener.addheaders = [('user-agent', "mozilla/5.0 (windows nt 5.1) applewebkit/537.36 (khtml, gecko) chrome/28.0.1500.72 safari/537.36")] forms = {"username": self.username, "password": self.password } data = urllib.urlencode(forms) req = urllib2.request('http://www.example.com/login.phtml',data) res = self.opener.open(req) self.login_html = res.read() if 'welcome neopets!' in self.login_html: print 'login sucsessful!' break else: print 'failed login'
that works both accounts here buy shares method:
def buy_shares(self): self.opener.addheaders = [('referer','http://example.com/stockmarket.phtml?type=buy')] site = self.opener.open('http://www.example.com/stockmarket.phtml?type=list&full=true') html = site.read() soup = beautifulsoup(html) text_list = [] stocks_list = [] in soup.findall('b'): text_list.append(i.get_text()) start = text_list.index('change')+1 stop = text_list.index('search :') in range(start,stop): stocks_list.append(text_list[i]) stocks = [stocks_list[i:i+4] in range(0, len(stocks_list), 4)] in stocks: if i[2] == '17': stock_name = (i[0]).encode('utf-8') print stock_name break else: stock_name = none if stock_name != none: print "buying" forms1 = {"ticker_symbol" : stock_name, "amount_shares": "1000", "type" : "buy", "_ref_ck" : "587d56547765f577cfdaaa3a7ac8328c" } data1 = urllib.urlencode(forms1) req1 = urllib2.request('http://www.example.com/process_stockmarket.phtml?',data1) res1 = self.opener.open(req1) html = res1.read() print html if 'portfolio' in html: print 'sucsess' elif stock_name == none: print "no stock buy" self.sell_shares()
like said program works account when try friends account error in html output
i cant figure out why works 1 , not other im thinking maybe because browser has account remembered im not sure
someone please been working on hours!
thank you!
update
so cleared saved passwords browser , neither of them work think fact had password saved why isnt working when dont have password saved?
either cookies don't match or "_ref_ck" : "587d56547765f577cfdaaa3a7ac8328c"
user specific value.
Comments
Post a Comment