def GetGrades(numberP, password): br = RoboBrowser() br.open('https://m.portal.ufp.pt/', verify=False) form = br.get_form() form['utilizador'] = numberP form['password'] = password br.submit_form(form) src = str(br.parsed()) start = '<div id="headertitle">UFP - ' end = '</div>' resultN = re.search("%s(.*)%s" % (start, end), src).group(1) number = "" for x in range(0, 5): # retiramos só numero do utilizador number += resultN[x] if number == numberP: # se for igual vamos buscar as notas br.open('https://m.portal.ufp.pt/notas.php', verify=False) src = str(br.parsed()) soup = BeautifulSoup( src, "html.parser") # enbelezamos e indexamos para formato HTML comments = soup.find_all( string=lambda text: isinstance(text, Comment) ) # na página da UFP as notas encontra-se num comentário na página , o que torna o processo mais simples return json.loads(comments[0].encode( 'utf-8')) # colocamos o resultado em formato JSON else: return false
def check_cred(rno, pas): status = check_url() if (status == "down"): return jsonify({'site': 'down'}) else: br = RoboBrowser(history=True, parser="html.parser") br = RoboBrowser( user_agent= 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6' ) br.open('http://studentscorner.vardhaman.org') form = br.get_form(action="") form["rollno"] = rno form["wak"] = pas br.submit_form(form) checkrno = str(br.select) if (rno in checkrno): br.open( "http://studentscorner.vardhaman.org/student_information.php") bt = br.parsed() th = br.select("th") #3 td = br.select("td") #8 name = str(td[8].text.strip()) print("In check_pas", finalurl) return jsonify({ 'valid': 'True', 'rollno': rno, 'pas': pas, 'name': name }) else: return jsonify({'valid': 'False'})
def grabkeys(cfg): if not cfg: return False br = RoboBrowser() br.open('http://makemkv.com/forum2/viewtopic.php?f=12&t=16959') pageStr = str(br.parsed()) i = 1 def get_key_link(base_link): global i, pageStr beg = pageStr.find(base_link) strLength = len(base_link) while True: link = pageStr[beg:beg + strLength + i] print(link) if pageStr[beg + strLength:beg + strLength + i].isnumeric() is False: return link[:-1] i = i + 1 # print(get_key_link()) os.system('tinydownload -o keys_hashed.txt ' + get_key_link('http://s000.tinyupload.com/index.php?file_id=')) br.open('https://forum.doom9.org/showthread.php?t=175194') pageStr = str(br.parsed()) i = 1 os.system('tinydownload -o KEYDB.cfg ' + get_key_link('http://s000.tinyupload.com/index.php?file_id=')) os.system('mv -u -t /home/arm/.MakeMKV keys_hashed.txt KEYDB.cfg')
def show(self): browser = RoboBrowser(parser = 'html.parser') browser.open('http://codeforces.com/enter') enter_form = browser.get_form('enterForm') enter_form['handleOrEmail'] = self.username enter_form['password'] = self.password browser.submit_form(enter_form) try: checks = list(map(lambda x: x.getText()[1:].strip(), browser.select('div.caption.titled'))) if self.username not in checks: Colour.print('Login Failed.. Wrong password.', Colour.RED) return except Exception as e: Colour.print('Login Failed.. Maybe wrong id/password.', Colour.RED) return browser.open('http://codeforces.com/friends') soup = browser.parsed()[0] # no need of soup ftable = soup.findAll('div',{'class':'datatable'})[0].findAll('table')[0].findAll('tr')[1:] friends = [x.findAll('td')[1].getText().strip() for x in ftable] for f in friends: print(f)
def get_atd(rno, pas, tid): if tid in gid: tindex = gid.index(tid) rno = rid[tindex] pas = pid[tindex] print(rno, pas) else: return ("First Login") #Below code can also be written in if block. This is also correct as else returns below code will not execute. br = RoboBrowser(history=True, parser="html.parser") br = RoboBrowser( user_agent= 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6' ) br.open('http://studentscorner.vardhaman.org') form = br.get_form(action="") form["rollno"] = rno form["wak"] = pas br.submit_form(form) br.open("http://studentscorner.vardhaman.org/student_attendance.php") bt = br.parsed() th = br.select("th") #3 td = br.select("td") #8 #print str(th[55].text.strip())+":"+str(th[56].text.strip())#attend try: for i in range(46, 56): if (str(th[i].text.strip()) == "Attendance Percentage"): if (finalurl != "http://studentscorner.vardhaman.org/"): return str(th[i].text.strip()) + ":" + str( th[i + 1].text.strip()) #attend except IndexError: return ("Attendance is Freesed")
def get_det(tid): tindex = gid.index(tid) rno = rid[tindex] pas = pid[tindex] print(rno, pas) br = RoboBrowser(history=True, parser="html.parser") br = RoboBrowser( user_agent= 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6' ) br.open('http://studentscorner.vardhaman.org') form = br.get_form(action="") form["rollno"] = rno form["wak"] = pas br.submit_form(form) #br.open("http://studentscorner.vardhaman.org")''' print(rno) #bot.reply_to(m,"wait") br.open("http://studentscorner.vardhaman.org/student_information.php") bt = br.parsed() th = br.select("th") #3 td = br.select("td") #8 print("In details " + rno) #print(z.geturl()) #if finalurl != "http://studentscorner.vardhaman.org/": try: return (str(th[3].text.strip()) + ":" + str(td[8].text.strip()) + "\n" + str(th[10].text.strip()) + ":" + str(td[17].text.strip()) + "\n" + str(th[29].text.strip()) + ":" + (str(td[33].text.strip())) + "\n" + str(th[31].text.strip()) + ":" + str(td[35].text.strip()) ) #details except IndexError: return ("Something is wrong")
def valid_login(uname, pwd, proxies=False): """ uname: str pwd: str proxies: dict ({'http': 'http://my.proxy.com/'}) """ if proxies != False: session = Session() session.proxies = proxies browser = RoboBrowser(session=session, parser='lxml') else: browser = RoboBrowser(history=True,\ user_agent='Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1'\ ,parser='lxml') login_url = 'https://www.roblox.com/account/signupredir' browser.open(login_url) form = browser.get_form(action='https://www.roblox.com/newlogin') form['username'].value = uname form['password'].value = pwd browser.submit_form(form) source = str(browser.parsed()) if "Hello, %s!" % uname in source: return True else: return False
def new_token(): random_string = ''.join( random.choice(string.ascii_uppercase + string.digits) for _ in range(16)) from robobrowser import RoboBrowser browser = RoboBrowser() login_url = 'my_url' browser.open('https://github.com/login') form = browser.get_form() # print(form) form["login"].value = "thirstycode" form["password"].value = "" # print(form) browser.submit_form(form) browser.open('https://github.com/settings/tokens/new') form = browser.get_forms() # print(form) form[3]["oauth_access[description]"].value = random_string form[3]["oauth_access[scopes][]"].value = [ 'repo', 'admin:org', 'admin:public_key', 'admin:repo_hook', 'admin:org_hook', 'gist', 'notifications', 'user', 'delete_repo', 'write:discussion', 'admin:gpg_key' ] browser.submit_form(form[3]) # print(browser.parsed()) src = str(browser.parsed()) start = '<code class="token" id="new-oauth-token">' end = '</code>' result = re.search('%s(.*)%s' % (start, end), src).group(1) return (result) print(result)
def date_wise_activity_diary(rno, pas): br = RoboBrowser(history=True, parser="html.parser") br = RoboBrowser( user_agent= 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6' ) br.open('http://studentscorner.vardhaman.org') form = br.get_form(action="") form["rollno"] = rno form["wak"] = pas br.submit_form(form) br.open( "http://studentscorner.vardhaman.org/Studentwise_AttendanceRegister.php" ) bt = br.parsed() th = br.select("th") #3 td = br.select("td") #8 l = [] att = [] #print str(th[55].text.strip())+":"+str(th[56].text.strip())#attend try: for i in range(10, 99): if (str(th[i].text.strip()) == "Attendance Percentage"): print(str(th[i + 1].text.strip())) return (str(th[i + 1].text.strip())) #if(finalurl != "http://studentscorner.vardhaman.org/"): #att.append("\033[1m"+str(th[i].text.strip())+" : *"+str(th[i+1].text.strip())+"*") # bot.send_message(tid,str(th[i].text.strip())+" : *"+str(th[i+1].text.strip())+"*",parse_mode= 'Markdown')#attend except IndexError: return ( "Attendance is Freesed.If attendance is not freesed you can see it in the website send the mail to the developer stating the issue." )
def classes_and_teachers_dep(nivel, departamento, ano, periodo): br = RoboBrowser(parser='lxml') br.open( 'https://sigaa.ufpb.br/sigaa/public/turmas/listar.jsf?aba=p-ensino') # Filling form for Class search form = br.get_form(id='formTurma') form['formTurma:inputNivel'].value = nivel form['formTurma:inputDepto'].value = departamento form['formTurma:inputAno'] = ano form['formTurma:inputPeriodo'].value = periodo buscar = form['formTurma:j_id_jsp_1323203740_14'] br.submit_form(form, submit=buscar) src = str(br.parsed()) page_soup = soup(src, "html.parser") container = page_soup.find("table", {"class": "listagem"}) raw_data = container.find_all("tr") # Unwanted page data raw_data = raw_data[1:-1] teachers_and_classes = list(each.text.strip().split("\n") for each in raw_data) teachers_and_classes[0] = [teachers_and_classes[0][-1] ] # Removing useless server data return teachers_and_classes
def get_cookies(self): """ opens a fake browser to get the cookies needed """ from robobrowser import RoboBrowser browser = RoboBrowser( user_agent= 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1b3) Gecko/20090305 Firefox/3.1b3 GTB5', parser='html.parser') browser.open('https://battlemap.deltatgame.com/home#') link = browser.find('a') browser.follow_link(link) form = browser.get_form(0) with open('battlecreds.json') as credentialfile: credentials = json.load(credentialfile) form['Email'] = credentials['email'] browser.submit_form(form) form = browser.get_form(0) form['Passwd'] = credentials['password'] browser.submit_form(form) browser.open('https://battlemap.deltatgame.com/home') self.battlemap_token = browser.session.cookies.get('battlemap_session') self.xsrf = browser.session.cookies.get('XSRF-TOKEN') self.cookietimeout = time.time() + 60 * 60 * 1.95 # GET csrf-token META HERE self.csrf = '' self.brow = browser from bs4 import BeautifulSoup soup = BeautifulSoup(str(browser.parsed()), "html.parser") for tag in soup.find_all('meta'): if 'name' in tag.attrs and tag.attrs['name'] == 'csrf-token': self.csrf = tag.attrs['content']
def show(self): browser = RoboBrowser(parser = 'html.parser') browser.open('http://codeforces.com/enter') enter_form = browser.get_form('enterForm') enter_form['handleOrEmail'] = self.username enter_form['password'] = self.password browser.submit_form(enter_form) try: checks = list(map(lambda x: x.getText()[1:].strip(), browser.select('div.caption.titled'))) if self.username not in checks: Colour.print('Login Failed.. Wrong password.', Colour.RED) return except Exception as e: Colour.print('Login Failed.. Maybe wrong id/password.', Colour.RED) return browser.open('http://codeforces.com/contest/'+self.c_name+'/standings/friends/true') soup = browser.parsed()[0] # no need of soup ftable = soup.findAll('table',{'class':'standings'})[0].findAll('tr')[1:-1] tableh = soup.findAll('table',{'class':'standings'})[0].findAll('tr')[0].findAll('th') table_data = [[x.getText().strip() for x in tableh]] for friend in ftable: row = [x.getText().strip() for x in friend.findAll('td')] table_data += [row] tt = texttable.Texttable() tt.add_rows(table_data) tt.set_cols_valign(["b"]*len(tableh)) print(tt.draw())
def cgpa(rno, pas): br = RoboBrowser(history=True, parser="html.parser") br = RoboBrowser( user_agent= 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6' ) br.open('http://studentscorner.vardhaman.org') form = br.get_form(action="") form["rollno"] = rno form["wak"] = pas br.submit_form(form) br.open( "http://studentscorner.vardhaman.org/src_programs/students_corner/CreditRegister/credit_register.php" ) bt = br.parsed() th = br.select("th") #3 td = br.select("td") #8 c = str(br.select) t = "Cumulative Grade Point Average" i = c.index(t) try: return (str(th[1].text.strip()) + ":" + str(td[7].text.strip()) + "\n" + "Cumulative Grade Point Average:" + c[i + 33] + c[i + 34] + c[i + 35] + c[i + 36]) except IndexError: return ( "Something went wrong send the report to [email protected] stating the issue, with your rollno" )
def period_attendance(rno, pas): stat = check_url( rno, pas, "http://studentscorner.vardhaman.org/student_attendance.php") if (stat == "down"): return ("down") else: d = {} br = RoboBrowser(history=True, parser="html.parser") br = RoboBrowser( user_agent= 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6' ) br.open('http://studentscorner.vardhaman.org') form = br.get_form(action="") form["rollno"] = rno form["wak"] = pas br.submit_form(form) br.open("http://studentscorner.vardhaman.org/student_attendance.php") bt = br.parsed() th = br.select("th") #3 td = br.select("td") #8 l = [] att = [] try: for i in range(1, 49, 4): present = td[i + 3].text.strip() #Present period = td[i + 1].text.strip() #Period topic = td[i + 2].text.strip() #Topic present = present.upper() topic = topic[0].upper() + topic[1:].lower() # print(td[i],present, period, topic) if (present == "PRESENT"): #att.append("\033[1m"+str(td[i].text.strip())+" "+str(td[i+1].text.strip()) +" "+d+" -<b>"+t+"</b>") temp_dict = { str(td[i].text.strip()): present + "_-_" + period + "_-_" + topic } d.update(temp_dict) else: #att.append("\033[1m"+str(td[i].text.strip())+" "+p+" "+d+" - ~<i>"+t+"</i>~") #bot.send_message(tid,str(td[i].text.strip())+" "+p+" "+d+" - ~<i>"+t+"</i>~",parse_mode= 'Html')#attend) temp_dict = { str(td[i].text.strip()): present + "_-_" + period + "_-_" + topic } d.update(temp_dict) #break except IndexError: pass if (not d): d = {"status": "None"} pa = json.dumps(d) return (pa) else: temp_dict = {"status": "True"} d.update(temp_dict) pa = json.dumps(d) print(type(pa)) return (pa)
def getStationFare(fro, to, url): br = RoboBrowser(history=True, parser="html.parser") br.open(url) form = br.get_form() form['ctl00$MainContent$ddlFrom'].value = str(fro) form['ctl00$MainContent$ddlTo'].value = str(to) br.submit_form(form) src = str(br.parsed()) return src
def attendance(tid, rno, pas): br = RoboBrowser(history=True, parser="html.parser") br = RoboBrowser( user_agent= 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6' ) br.open('http://studentscorner.vardhaman.org') form = br.get_form(action="") form["rollno"] = rno form["wak"] = pas br.submit_form(form) br.open("http://studentscorner.vardhaman.org/student_attendance.php") bt = br.parsed() th = br.select("th") #3 td = br.select("td") #8 l = [] att = [] #print str(th[55].text.strip())+":"+str(th[56].text.strip())#attend try: for i in range(40, 60): if (str(th[i].text.strip()) == "Attendance Percentage"): #if(finalurl != "http://studentscorner.vardhaman.org/"): #att.append("\033[1m"+str(th[i].text.strip())+" : *"+str(th[i+1].text.strip())+"*") bot.send_message(tid, str(th[i].text.strip()) + " : *" + str(th[i + 1].text.strip()) + "*", parse_mode='Markdown') #attend except IndexError: bot.send_message( tid, "*Attendance is Freesed*.\nIf attendance is not freesed you can see it in the website send the mail to \n *[email protected]*\nstating the issue.", parse_mode='Markdown') try: for i in range(9, 37, 4): t = td[i + 3].text.strip() p = td[i + 1].text.strip() d = td[i + 2].text.strip() t = t.upper() d = d[0].upper() + d[1:].lower() if (t == "PRESENT"): #att.append("\033[1m"+str(td[i].text.strip())+" "+str(td[i+1].text.strip()) +" "+d+" - <b>"+t+"</b>") bot.send_message(tid, str(td[i].text.strip()) + " " + str(td[i + 1].text.strip()) + " " + d + " - <b>" + t + "</b>", parse_mode='Html') #attend) else: #att.append("\033[1m"+str(td[i].text.strip())+" "+p+" "+d+" - ~<i>"+t+"</i>~") bot.send_message(tid, str(td[i].text.strip()) + " " + p + " " + d + " - ~<i>" + t + "</i>~", parse_mode='Html') #attend) #break except IndexError: pass return 1
def loginPart(url="http://classroom.dwit.edu.np"): br = RoboBrowser() br.open(url) form = br.get_form() form['username'] = config.username form['password'] = config.password br.submit_form(form) src = str(br.parsed()) return src
def disciplinasByCurso(course_id, year, period): br = RoboBrowser(parser='lxml') br.open( f"https://sigaa.ufpb.br/sigaa/public/curso/turmas.jsf?lc=pt_BR&id={course_id}" ) form = br.get_form(id='form') form['form:inputAno'] = year form['form:inputPeriodo'].value = period submit = form['form:j_id_jsp_771677251_40'] br.submit_form(form, submit=submit) src = str(br.parsed()) page_soup = soup(src, "html.parser") container = page_soup.find("div", {"id": "turmasAbertas"}) tables = container.find_all("table") turmas = [] for table in tables: disciplina = table.find("td", {"class": "subListagem"}) disciplina = disciplina.text.strip().split(";")[-1] codigo, nome = disciplina.split(" - ")[:2] # "CODIGO - DISCIPLINA" # EM CADA DISCIPLINA, ENCONTRE TODAS TURMAS tms = table.tbody.find_all("tr") for tm in tms: fields = tm.find_all("td") # CAMPOS turma = fields[1].text.strip() professor = fields[2].text.strip().replace("\t", "").replace("\n", "") horario = fields[4].text.strip() turmas.append({ "id": codigo, "nome": nome, "turma": turma, "professor": professor, "horario": horario, "idCurso": int(course_id) }) return turmas
def get_templates(): """Return all Pixelarity templates in an array.""" templates = [] browser = RoboBrowser() browser.open("https://pixelarity.com/") r = browser.parsed() soup = BeautifulSoup(str(r[0]), "html.parser") t = soup.find("section").find_all("article") for index in range(len(t)): templates.append(t[index].a.get("href").replace("/", "")) templates = [item.lower() for item in templates] templates = [item.replace(" ", "") for item in templates] return templates
def get_templates(): templates = [] browser = RoboBrowser() browser.open('https://pixelarity.com/') r = browser.parsed() soup = BeautifulSoup(str(r[0]), 'html.parser') t = soup.find("section").find_all("article") for index in range(len(t)): templates.append(t[index].h2.string) templates = [item.lower() for item in templates] templates = [item.replace(" ", "") for item in templates] return templates
def authenticate(self, user_email, password): # Get the signup form and set the values browser = RoboBrowser() browser.open('http://www.goodreads.com') signup_form = browser.get_form(id='sign_in') signup_form['user[email]'].value = user_email signup_form['user[password]'].value = password #submit the signup form browser.submit_form(signup_form) p = browser.parsed() #p is the page after submitting the form, if the returned file has 'My Books' only if the user is authenticated page = str(p) if "My Books" not in page: print("Login failed !") return False else: print("Login success !") return True
def get(self, request, registration): url = "http://mis.mptransport.org/MPLogin/eSewa/VehicleSearch.aspx" br = RoboBrowser(parser='html.parser') br.open(url) x = br.get_form(id='aspnetForm') x['ctl00$ContentPlaceHolder1$txtRegNo'] = registration br.submit_form(x) a = str(br.parsed()) soup = BeautifulSoup(a, "html.parser") table = soup.find("table", { "border": "1", "id": "ctl00_ContentPlaceHolder1_grvSearchSummary" }) for row in table.findAll('tr', {'class': 'GridItem'}): col = row.findAll('td') a = col[2].find('a').string b = col[3].string c = col[4].string d = col[5].string e = col[6].string f = col[7].string g = col[8].string h = col[10].string i = col[11].string j = col[12].string k = col[13].string l = col[14].string data = { 'registration_num': a, 'chassis no': b, 'engine no': c, 'owner_name': d, 'rto_name': e, 'manu year': f, 'regis_date': g, 'issued on': h, 'colour': i, 'class': j, 'maker': k, 'model': l, } #response = json.dumps(data) return JsonResponse(data, safe=False)
def findPollingPlace(address, zip_code): try: br = RoboBrowser() br.open("https://vt.ncsbe.gov/PPLkup/") form = br.get_form() form['StreetAddress'] = address form['City'] = "Durham" form['Zip'] = zip_code br.submit_form(form) polling_address_raw = str(br.parsed()) start = 'q=' end = ',DURHAM' polling_address = re.search('%s(.*)%s' % (start, end), polling_address_raw).group(1) polling_address_copy = polling_address polling_address = formatAddress(polling_address_copy) return polling_address except: #if no result returned try changing East, West, North or South to EWN orS return 'n/a'
def GetCreditsLicenciatura(): br = RoboBrowser() br.open('http://ingresso.ufp.pt/engenharia-informatica/#study-plan',verify=False) src = str(br.parsed()) soup = BeautifulSoup(src, "html.parser") td= soup.find_all('div',class_='row uc') credit=0 cred=dict() optcounter=0 for x in range(0, 31): st = td[x].get_text()[:-1].encode('utf-8') # codificação utf-8 devido a caracteres especiais if st == "Opção (a)": # if necessário devido à insconsintencia da infomação nas duas páginas, e para distinguir a opção senão é atualizada no dicionário if optcounter==0: st = "Opcão I" optcounter=1 else: st = "Opcão II" credit = len(td[x].get_text())-1 #Obtem posição de credito na string cred[st] = td[x].get_text()[credit]# Guardar no dicionário print(prepareJson(cred)) #Imprime dicionário com estrutura de json
def Login(matricula, senha): url = 'https://portalence.ibge.gov.br/gcad-aluno/' br = RoboBrowser() br.open(url) form = br.get_form() form['login-form:matricula-aluno'] = matricula form['login-form:j_idt22'] = senha br.submit_form(form) page = str(br.parsed()) loged = False name = '' if '<!-- L O G I N & N O M E-->' in page: loged = True start = 'Nome: ' end = ' ' name = re.search('%s(.*)%s' % (start, end), page).group(1) name = name.lower() return {'status': loged, 'name': name}
def browse(usr, pas): print('b-1') rand_prox = (proxi.random_proxy()) print(rand_prox.get_dict()) ses = requests.Session() print('b-2') ses.verify = False print('b-3') ses.proxies = rand_prox.get_dict() print('b-4') #ip=ses.get("https://api.ipify.org/").read() #print (str(ip)[2:-1]) rb = RoboBrowser(session=ses, parser='lxml', user_agent=ua.random, cache=False, allow_redirects=True, tries=3, timeout=20, history=False) print('b-5') #rb.open('https://api.ipify.org/') #print(str(rb.parsed()).encode()) rb.open('https://www.win6etyes.xyz/Account/Login') print('b-6') form = rb.get_form() print('b-7') form['UserName'] = usr print('b-8') form['Password'] = pas print('b-9') rb.submit_form(form) print('b-10') src1 = str(rb.parsed()).encode() print('b-11') src = (str(src1)) print(src[0:10]) return src
def fetch_highscores(first_name): # First, a RoboBrowser opens the highscores list. br = RoboBrowser() br.open('https://secure.runescape.com/m=hiscore_oldschool/hiscorepersonal') # To access a player's highscores, we must have RoboBrowser enter their username in the # 'search player' form. There are multiple forms on the page, but the 'search player' # form is the first one. form = br.get_forms()[0] # 'user1' is the name attribute of the form. We get the username from the first name using # the file 'usernames'. The purpose of a separate file for usernames is so I can present # this code but keep my friends and my usernames a secret. form.fields['user1'].value = get_username(first_name) # Sumbit the form. We are now in first_name's highscores page. br.submit_form(form) # src is a long HTML string which we will look through for the total level. src = str(br.parsed()) # Here is use BeautifulSoup. It's probably not necessary to switch from RoboBrowser, but # it was easier for me to get the code working. soup = BeautifulSoup(src, features='html.parser') # At the time of writing this code, 'class_ = centerDiv' is the closest location for the # total level. posts = soup.find_all(class_='centerDiv') player_string = posts[0].get_text() # 'player_string' has a lot of new line characters, and I only want one piece of the string. # So, I turn the string into a list using newline characters as the break points. player_list = player_string.splitlines() # The total level is at index number 47, so extract it. total_level = player_list[47] return total_level
def get_login_token(uname, pwd, proxy): """ uname: str pwd: str proxies: str ip:port """ proxies = {} proxies['http'] = proxy if proxies != False: session = Session() session.proxies = proxies browser = RoboBrowser(session=session, parser='lxml') else: browser = RoboBrowser(history=True,\ user_agent='Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1'\ ,parser='lxml') login_url = 'https://www.roblox.com/account/signupredir' browser.open(login_url) form = browser.get_form(action='https://www.roblox.com/newlogin') form['username'].value = uname form['password'].value = pwd browser.submit_form(form) source = str(browser.parsed()) return str(browser.session.cookies['.ROBLOSECURITY'])
def authenticate_user(self, user_email, password): # Set the users input values and read the home page webpage = RoboBrowser() goodreads_page = 'http://www.goodreads.com' # best practice: page can be changed whenever needed webpage.open(goodreads_page) # load and submit the login form using the get_form function login_form = webpage.get_form(id='sign_in') login_form['user[email]'].value = user_email login_form['user[password]'].value = password webpage.submit_form(login_form) # read the web page again and check for certain tags only visible after login to verify the user # another method could be hitting the database for verifying using dynamic querry building home_page = str(webpage.parsed()) if "Currently Reading" in home_page: print("User Authenticated") return True else: print("Invalid user creditentials") return False
def sgpa(rno, pas, semid): br = RoboBrowser(history=True, parser="html.parser") br = RoboBrowser( user_agent= 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6' ) br.open('http://studentscorner.vardhaman.org') form = br.get_form(action="") form["rollno"] = rno form["wak"] = pas br.submit_form(form) br.open( "http://studentscorner.vardhaman.org/src_programs/students_corner/CreditRegister/credit_register.php" ) bt = br.parsed() th = br.select("th") #3 td = br.select("td") #8 c = str(br.select) index = { "1": "13", "2": "17", "3": "21", "4": "25", "5": "29", "6": "33", "7": "37", "8": "41" } i = int(index[semid]) try: return (str(th[1].text.strip()) + ":" + str(td[7].text.strip()) + "\n" + str(th[i].text.strip())) except IndexError: return ( "I think you have not completed that semester.\nIf you have completed send your rollno to [email protected] stating the issue." )
from robobrowser import RoboBrowser my_url='http://yifyhdtorrent.com/' file_name='yify.csv' f=open(file_name,'w') headers='MOVIE_NAME,RATINGS\n' f.write(headers) browser=RoboBrowser(history=True) browser.open(my_url) browser.parsed('html') containers=browser.find_all('div',attrs={'class':'smp-view'}) for container in containers: name_container=container.find('div',attrs={'class':'title-video'}) movie_name=name_container.a name=movie_name.text ratings=container.div.text.strip() #print('NAME : '+name+' \nRatings :'+ ratings[0] +'\n') f.write(name+','+ratings[0]+'\n') f.close()
data_form # Fill it out i=0 d=0 j=0 for d in range(0,5): browser.open('http://myaccount.snu.edu.in') data_form['userNetId'].value = batch_2014_netids[x] data_form['startDate'].value = dates[j] data_form['endDate'].value = dates[j+1] j=j+2 # And submit browser.submit_form(data_form) html_doc =str(browser.parsed()) soup= BeautifulSoup(html_doc,'html.parser') str1=soup.text str2="Total in GB" str3="GB: 0" str4="GB: 0." str5=str1[str1.find(str2) + 17*2 +1 :str1.find(str2)+(17*3)+5] str7=str5.replace(":"," ") #all print statements can be removed without affecting the database output if str5.find(str3)>0 and \ str5.find(str4)<0: print(batch_2014_netids[x]) else: