How to use _get_base64 method in localstack

Best Python code snippet using localstack_python

Spider_CMCC.py

Source:Spider_CMCC.py Github

copy

Full Screen

...86 _get_Randomcode_resp = self.session.get(url=_get_Randomcode_url, params=query_string, headers=Headers)87 logging.info('_get_Randomcode_resp: %s' % _get_Randomcode_resp.text)88 sms_random_code = input('请输入二次短信验证码:')89 return sms_random_code90 def _get_base64(self, pwd):91 pwd_byte = bytes(pwd, encoding='utf-8')92 base64_pwd = base64.b64encode(pwd_byte)93 return str(base64_pwd, encoding='utf-8')94 def _get_tempident(self, phone_num, pwd, sms, cap):95 _get_tempident_url = 'https://shop.10086.cn/i/v1/fee/detailbilltempidentjsonp/{0}'.format(phone_num)96 query_string = {97 'callback': 'jQuery1830' + str(int(random.random() * 100000000000000000)),98 'pwdTempSerCode': self._get_base64(pwd),99 'pwdTempRandCode': self._get_base64(sms),100 'captchaVal': cap,101 '_': int(time.time() * 1000),102 }103 Headers = {104 'Host': 'shop.10086.cn',105 'Connection': 'keep-alive',106 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) '107 'Chrome/66.0.3359.139 Safari/537.36',108 'Accept': '*/*',109 'Referer': 'http://shop.10086.cn/i/?f=billdetailqry&welcome=1525251281507',110 'Accept-Encoding': 'gzip, deflate, br',111 'Accept-Language': 'zh-CN,zh;q=0.9',112 }113 _get_tempident_resp = self.session.get(url=_get_tempident_url, params=query_string, headers=Headers)...

Full Screen

Full Screen

Bilibili.py

Source:Bilibili.py Github

copy

Full Screen

...39 duration = data1['data']['dash']['duration']40 jsonstr2 = re.findall(r'<script>window.__INITIAL_STATE__=(.*?);\(function\(\){',rep.text)[0]41 data2 = json.loads(jsonstr2)['videoData']42 cover_url = data2['pic']43 cover = self._get_base64(cover_url)44 artist = data2['owner']['name']45 name = data2['title']46 parse = urlparse(url)47 query = parse_qs(parse.query)48 music = Music("bilibili", bv, url, name, artist,49 cover, duration, ''.join(query['deadline']))50 return music.__dict__51 52 def search_keyword(self, kw):53 '''54 kw:搜索关键词55 return:一个列表,列表的每个元素是一个Music对象的字典形式56 '''57 url = "https://search.bilibili.com/all?keyword=" + \58 kw+"&order=totalrank&duration=1&tids_1=3"59 rep = requests.get(url)60 videos = []61 if(rep.status_code == 200):62 soup = BeautifulSoup(rep.text, "html.parser")63 video_dom = soup.find_all("li", {"class": "video-item matrix"})64 for i in range(len(video_dom)):65 bvurl = "https:"+video_dom[i].a['href']66 bv = urlparse(bvurl).path.split('/')[-1]67 duration = video_dom[i].a.find(68 "span", {"class": "so-imgTag_rb"}).string69 name = video_dom[i].a['title']70 music = Music('bilibili', bv, "", name, "", "", duration, "",albumname='')71 videos.append(music.__dict__.copy())72 return videos73 else:74 return []75 def get_recommendation(self):76 '''77 获取一个推荐列表78 return Music对象的字典格式列表79 '''80 today = datetime.date.today()81 formatted_today = today.strftime('%Y%m%d')82 before30days = (datetime.date.today() +83 datetime.timedelta(days=-30)).strftime('%Y%m%d')84 url = "https://s.search.bilibili.com/cate/search?main_ver=v3&search_type=video&view_type=hot_rank&order=click&copy_right=-1&cate_id=193&page=1&pagesize=20&jsonp=jsonp&time_from=" + \85 before30days+"&time_to="+formatted_today+"&keyword=%E5%8D%8E%E8%AF%ADMV"86 rep = requests.get(url)87 if(rep.status_code == 200):88 data = rep.json()['result']89 videos = []90 for i in range(len(data)):91 name = data[i]['title']92 duration = self._sec2MinSec(data[i]['duration'])93 id = data[i]['bvid']94 music = Music('bilibili', id, '', name, '', '', duration, '')95 videos.append(music.__dict__.copy())96 return videos97 else:98 return []99 #B站播放列表和视频在同页面下100 def get_playlist(self, bvid):101 '''102 bvid:B站视频id103 return 一个Playlist对象的字典形式104 '''105 videourl = "https://www.bilibili.com/video/"+bvid106 rep = requests.get(videourl)107 playlist = {}108 if (rep.status_code == 200):109 try:110 jsonstr = re.findall(r'<script>window.__INITIAL_STATE__=(.*?);\(function\(\){',rep.text)[0]111 data = json.loads(jsonstr)['videoData']112 id = data['bvid']113 cover_url = data['pic']114 cover = self._get_base64(cover_url)115 creatername = data['owner']['name']116 face = data['owner']['face']117 creatrecover = self._get_base64(face)118 name = data['title']119 items = []120 for item in data['pages']:121 music = Music('bilibili',id+str(item['page']),'',item['part'],creatername,'',str(item['duration']),'')122 items.append(music.__dict__)123 playlist = Playlist('bilibili',id,name,cover,creatername,creatrecover,items).__dict__124 125 except Exception:126 pass127 return playlist128 # 秒转分秒129 def _sec2MinSec(self, sec):130 return str(int(sec)//60)+':'+(str(int(sec) % 60 if(int(sec) % 60 >= 10) else '0'+str(int(sec) % 60)))131 def _get_base64(self, img_url):132 '''133 img_url:图片链接134 return base64编码后的图片135 '''136 resp = requests.get(img_url)137 img_bytes = base64.b64encode(BytesIO(resp.content).read())138 img_str = img_bytes.decode()139 return 'data:image/'+os.path.basename(img_url)+';base64,'+img_str140 def get_lyric(self,id):...

Full Screen

Full Screen

Youtube.py

Source:Youtube.py Github

copy

Full Screen

...13 video = pafy.new(videoUrl)14 parse = urlparse(video.audiostreams[-1].url)15 query = parse_qs(parse.query)16 music = Music("youtube", id, video.audiostreams[-1].url, video.title,17 video.author, self._get_base64(video.thumb), video.duration, ''.join(query['expire']))18 return music.__dict__19 def search_keyword(self, kw):20 #如果是一个播放列表链接,则提取listid21 if(len(re.findall(r'[&?]list=([^&]+)',kw))):22 return self.get_playlist(re.findall(r'[&?]list=([^&]+)',kw)[0])['items']23 url = "https://m.youtube.com/results?search_query="+kw24 resp = requests.get(url)25 if resp.status_code == 200:26 result_json = re.findall(27 r'ytInitialData = (.*);</script>', resp.text)[0]28 result_obj = json.loads(result_json)29 musiclist = []30 kwIsList=True31 for i in result_obj['contents']['twoColumnSearchResultsRenderer']['primaryContents']['sectionListRenderer']['contents'][0]['itemSectionRenderer']['contents']:32 if "videoRenderer" in i:33 kwIsList=False34 item = i["videoRenderer"]35 musicBuffer = Music('youtube', item['videoId'], "", item['title']['runs'][0]['text'],36 item['ownerText']['runs'][0]['text'], "", item['lengthText']['simpleText'], "",albumname='')37 musiclist.append(musicBuffer.__dict__.copy())38 #如果是listid39 elif "playlistRenderer" in i and kwIsList:40 musiclist += self.get_playlist(41 i['playlistRenderer']['playlistId'])42 return musiclist43 else:44 return []45 def get_playlist(self, listid):46 baseUrl = "https://www.youtube.com/playlist?app=desktop&list="+listid47 resp = requests.get(baseUrl)48 if(resp.status_code == 200):49 reg = r'ytInitialData =(.*?);</script>'50 dataStr = re.findall(reg, resp.text)[0]51 data = json.loads(dataStr)52 videos = []53 playlist = {}54 try:55 for item in data['contents']['twoColumnBrowseResultsRenderer']['tabs'][0]['tabRenderer']['content']['sectionListRenderer']['contents'][0]['itemSectionRenderer']['contents'][0]['playlistVideoListRenderer']['contents']: 56 item = item['playlistVideoRenderer']57 id = item['videoId']58 name = item['title']['runs'][0]['text']59 duration = item['lengthText']['simpleText']60 music = Music('youtube', id, "", name,61 "", "", duration, "")62 videos.append(music.__dict__.copy())63 name = data['microformat']['microformatDataRenderer']['title']64 cover_url = data['microformat']['microformatDataRenderer']['thumbnail']['thumbnails'][-1]['url']65 cover = self._get_base64(cover_url)66 creatername = data['sidebar']['playlistSidebarRenderer']['items'][-1]['playlistSidebarSecondaryInfoRenderer']['videoOwner']['videoOwnerRenderer']['title']['runs'][0]['text']67 creatercover_url = data['sidebar']['playlistSidebarRenderer']['items'][-1]['playlistSidebarSecondaryInfoRenderer']['videoOwner']['videoOwnerRenderer']['thumbnail']['thumbnails'][-1]['url']68 creatercover = self._get_base64(creatercover_url)69 playlist=Playlist('youtube',listid,name,cover,creatername,creatercover,videos).__dict__70 except KeyError:71 pass 72 73 return playlist74 else:75 print(resp.status_code)76 return {}77 def get_recommendation(self):78 return []79 def _get_base64(self, img_url):80 resp = requests.get(img_url)81 img_bytes = base64.b64encode(BytesIO(resp.content).read())82 img_str = img_bytes.decode()83 return 'data:image/'+os.path.basename(img_url)+';base64,'+img_str84 def get_lyric(self,id):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful