def test_get(self): #self.getdata.open('Get') nrows, table = self.getdata.open('Get') header = {'Authorization': 'Bearer ' + self.login()} #print(header) for i in range(1, nrows + 1): method, host, headers, data, res, api, msg, caseid = self.getdata.getdata( 'activity', i) #hea = eval(str(headers)) #print(i,nrows) if method == 'Path' or method == 'Query': #print(self.url) for l in range(data.__len__()): dt = data['data' + str(l + 1)] expect_res = res['res' + str(l + 1)] self.url = host + api + dt response = requests.get(self.url, headers=header, json=dt) code = response.status_code text = json.loads(response.text) self.analysis.judgement(code, text, expect_res, msg, dt, caseid, api) #print(code,text,result) else: url = host + api response = requests.get(url) print(response.status_code)
def action(self): self.getdata.condb() count = int(self.getdata.condb()) header = {'Authorization': 'Bearer ' + self.login()} for i in range(count): len,method,api,headers,data,datalen,host = self.getdata.getdata(i+1) if method == 'path' or method == 'Query': url = host+api+data requests.get(url,header = dict(headers,**header)) elif method == 'json': url = host+api requests.get(url = url,header = dict(headers,**header), json = data) elif method == 'null': url = host+api print(url) r = requests.get(url)
def _send_request(self, action, params=None): self.plugin.log(u'Send request for action: %s ' % action) if params is None: cloned_params = {} else: cloned_params = copy.deepcopy(params) login_info = self.get_login_info() if login_info is not None: cloned_params[login_info[u'sid_name']] = login_info[u'sid'] r = requests.get(IPTV_API % action, cloned_params, headers={ 'User-Agent': self.gen_ua(), 'Accept-Encoding': 'identity, deflate, compress, gzip' }) self.plugin.log('response retrieved %s' % r.elapsed) json_response = r.json() if u'error' in json_response: error_code = json_response[u'error'][u'code'] if error_code == 12: self.plugin.log(u'You are not logged, try to login', xbmc.LOGWARNING) self.do_authentication() return self.send_request(action, params) else: self.plugin.log(u"Response Error for %s: code - %s, message - %s" % ( action, json_response[u'error'][u'code'], json_response[u'error'][u'message']), xbmc.LOGERROR) raise ValueError(u"Response Error: code - %s, message - %s" % ( json_response[u'error'][u'code'], json_response[u'error'][u'message'])) return json_response
def download_file(url, loc): with requests.get(url, stream=True) as r: r.raise_for_status() with open(loc, "wb") as f: for chunk in tqdm(r.iter_content(chunk_size=258384)): if chunk: # filter out keep-alive new chunks f.write(chunk) # f.flush() return loc
def test_post(self): #self.getdata.open('Get') nrows, table = self.getdata.open('Post') header = {'Authorization': 'Bearer ' + self.login()} print(header) for i in range(nrows): method, host, headers, data, length, api = self.getdata.getdata( 'Post', i) #hea = eval(str(headers)) if method == 'Json': self.url = host + api d = json.loads(data) response = requests.get(self.url, headers=header, json=d) code = response.status_code content = response.content print(self.url) print(code, content) elif method == 'none': url = host + api response = requests.get(url) print(response.status_code, )
def get_user_id(tag, auth_header): url_user_id = '{}{}?rfid_tag={}'.format( API['URL'], API['PROFILES_ROUTE'], tag, ) r = requests.get(url_user_id, headers=auth_header) r_json = loads(r.content) if r_json: try: user_id = r_json[0]['user'] return user_id except: pass return None
def api_transactions_get(api_base_url, api_id, api_access_token, parameters): # This should print a contact from Aplos. # Lets show what we're doing. headers = {'Authorization': 'Bearer: {}'.format(api_access_token)} print('geting URL: {}transactions'.format(api_base_url)) print('With headers: {}'.format(headers)) # Actual request goes here. #parameters ={'f_rangestart': '2020-10-08', 'f_rangeend': '2020-10-08',} r = requests.get('{}./transactions'.format(api_base_url), headers=headers, params=parameters) api_error_handling(r.status_code) response = r.json() #print('JSON response: {}'.format(response)) #print(response) return (response)
def match_funds(api_base_url, api_id, api_access_token, batch_details): headers = {'Authorization': 'Bearer: {}'.format(api_access_token)} print('geting URL: {}funds'.format(api_base_url)) print('With headers: {}'.format(headers)) r = requests.get('{}funds'.format(api_base_url), headers=headers) api_error_handling(r.status_code) response1 = {} response1 = r.json() for i, v in batch_details["details"].items(): for i2 in response1["data"]["funds"]: if i == i2["name"]: v["id"] = i2["id"] if v["id"] == 62: sns.publish(TopicArn=sns_topic, Message="fund " + i + " does not match anything in aplos") quit() return (batch_details)
def api_auth(api_base_url, api_id, api_user_key): # This should return an authorized token so we can do other, more exciting things # Lets show what we're doing. print('geting URL: {}auth/{}'.format(api_base_url, api_id)) # Actual request goes here. r = requests.get('{}auth/{}'.format(api_base_url, api_id)) data = r.json() api_error_handling(r.status_code) api_token_encrypted = data['data']['token'] api_token_encrypted_expires = data['data']['expires'] print('The API Token expires: {}'.format(api_token_encrypted_expires)) #print(api_token_encrypted) api_bearer_token = rsa.decrypt(base64.b64decode(api_token_encrypted), api_user_key) api_bearer_token = api_bearer_token.decode("utf-8") return (api_bearer_token)
def gym_spider(gym): global display godziny = [] zajecia = [] url = 'http://fitnessplatinium.pl/'+gym+'/grafik/' source_code = requests.get(url) plain_text = source_code.text soup = BeautifulSoup(plain_text, "lxml") dni=['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] for hour in soup.findAll('td', {'class': 'hour'}): if hour.contents==[]: hour.contents=[''] godziny.append(hour.contents) for n,i in enumerate(godziny): if i==['']: godziny[n]=godziny[n-1] temp=[] for a in godziny: if isinstance(a, list): temp.extend(a) for aula in soup.findAll('td', {'class': 'active'}): if aula.contents==None: aula.contents=[] else: aula.contents=str(aula.findAll('h6'))[5:-6] zajecia.append([aula.contents]) for c in zajecia: if "&" in c[0]: c[0]=c[0].replace("&","&") c.append(dni[zajecia.index(c)%7]) c.append(str(temp[int(zajecia.index(c)/7)])) c.append(gym) klasy=[] for c in zajecia: if c[0]!='': klasy.append(c) for klasa in klasy: display+='<tr>' for info in klasa: display+='<td style="text-align:center">'+str(info)+'</td>' display+='</tr>'
def main(): link = 'https://api.syncromatics.com/portal/stops/3249689/arrivals?count=5&routeId=3354&api-key=302ab81bc3e3f2058b355c3ef29ec2402608e358f303e429c81e01d9ad65d6e0' page = requests.get(link) soup = BeautifulSoup(page.text, 'html5lib') response = json.loads(soup.text) try: if (response[0]['secondsToArrival']) > 3600: print("No bus arrivals in the next hour.") result = "No bus arrivals in the next hour." else: mybus = response[0]['pattern'][ 'name'] + ' - Minutes to Arrival: ' + str( round(response[0]['secondsToArrival'] / 60, 0)) print(mybus) result = mybus except: print("There are no more bus arrivals today.") result = "There are no more bus arrivals today." return result
def _send_request(self, action, params=None): self.plugin.log(u'Send request for action: %s ' % action) if params is None: cloned_params = {} else: cloned_params = copy.deepcopy(params) login_info = self.get_login_info() if login_info is not None: cloned_params[login_info[u'sid_name']] = login_info[u'sid'] r = requests.get(IPTV_API % action, cloned_params, headers={ 'User-Agent': self.gen_ua(), 'Accept-Encoding': 'identity, deflate, compress, gzip' }) self.plugin.log('response retrieved %s' % r.elapsed) json_response = r.json() if u'error' in json_response: error_code = json_response[u'error'][u'code'] if error_code == 12: self.plugin.log(u'You are not logged, try to login', xbmc.LOGWARNING) self.do_authentication() return self.send_request(action, params) else: self.plugin.log( u"Response Error for %s: code - %s, message - %s" % (action, json_response[u'error'][u'code'], json_response[u'error'][u'message']), xbmc.LOGERROR) raise ValueError(u"Response Error: code - %s, message - %s" % (json_response[u'error'][u'code'], json_response[u'error'][u'message'])) return json_response
def index(): rep = rq.get("http://127.0.0.1:5000", cookies=cookie) print(rep.text)
import requests.requests r = requests.get('https://api.github.com/events') print ("hello fags")
def get(self, resource, **kw): return requests.get(self.url(resource), auth=(self._username, self._password), verify=self._verify, **kw)
from bs4 import BeautifulSoup from requests import requests response = requests.get( 'https://www.enchantedlearning.com/wordlist/opposites.shtml') html = str(response.text) soup = BeautifulSoup(html, "html.parser") divs = soup.find_all("div", "wordlist-item") the_file = open("opposites.txt", "w") for div in divs: text = str(div.get_text()) res = text.partition(",")[0] print(str(res)) the_file.write(str(res) + "\n")
def getaccount(names): print(names) resp = rq.get("http://127.0.0.1:5000/account/%s" % (names)) print(resp.text)
def nextLink(self): link = requests.get( "http://localhost/silicon/?nextLink&machine=127.0.0.2").text return link
from requests import requests page = requests.get( "http://dataquestio.github.io/web-scraping-pages/simple.html") page
from requests import requests requests.get('http://www.baidu.com') url = 'https://github.com/timeline.json' requests.get(url)