Best Python code snippet using playwright-python
downloadcontroller.py
Source: downloadcontroller.py
...21 def init_routes(self):22 @self.app.get('/<user>/<coll>/<rec>/$download')23 def logged_in_download_rec_warc(user, coll, rec):24 self.redir_host()25 return self.handle_download(user, coll, rec)26 @self.app.get('/<user>/<coll>/$download')27 def logged_in_download_coll_warc(user, coll):28 self.redir_host()29 return self.handle_download(user, coll, '*')30 def create_warcinfo(self, creator, title, metadata, source, filename):31 for name, value in iteritems(source):32 if name in self.COPY_FIELDS:33 metadata[name] = value34 info = OrderedDict([35 ('software', 'Webrecorder Platform v' + __version__),36 ('format', 'WARC File Format 1.0'),37 ('creator', creator),38 ('isPartOf', title),39 ('json-metadata', json.dumps(metadata)),40 ])41 wi_writer = BufferWARCWriter()42 wi_writer.write_record(wi_writer.create_warcinfo_record(filename, info))43 return wi_writer.get_contents()44 def create_coll_warcinfo(self, user, collection, filename=''):45 metadata = {}46 metadata['type'] = 'collection'47 title = quote(collection['title'])48 return self.create_warcinfo(user, title, metadata, collection, filename)49 def create_rec_warcinfo(self, user, collection, recording, filename=''):50 metadata = {}51 metadata['pages'] = self.manager.list_pages(user,52 collection['id'],53 recording['id'])54 metadata['type'] = 'recording'55 title = quote(collection['title']) + '/' + quote(recording['title'])56 return self.create_warcinfo(user, title, metadata, recording, filename)57 def handle_download(self, user, coll, rec):58 collection = self.manager.get_collection(user, coll, rec)59 if not collection:60 self._raise_error(404, 'Collection not found',61 id=coll)62 now = timestamp_now()63 name = collection['id']64 if rec != '*':65 rec_list = rec.split(',')66 if len(rec_list) == 1:67 name = rec68 else:69 name += '-' + rec70 else:71 rec_list = None...
DownloadUtils.py
Source: DownloadUtils.py
...8from utils.Bean import FileInfo9from utils.Constans import DOWNLOAD_PATH, MP4_TYPE, JPG_TYPE10from utils.CommonUtils import isNullOrBlank, get_index, isNull11from utils.FileUtils import get_valid_file_name, get_url_suffix, get_unique_file_name, write_file12def handle_download(url, name, suffix, header=None, file_path=DOWNLOAD_PATH):13 try:14 s = requests.Session()15 if header is not None:16 s.headers = header17 s.mount(url, HTTPAdapter(max_retries=5))18 downloaded = s.get(url, timeout=(5, 10))19 valid_name = get_valid_file_name(name)20 file_suffix = get_url_suffix(url, suffix)21 file_name = get_unique_file_name(valid_name + file_suffix)22 write_file(file_path + file_name, downloaded.content)23 print('ä¸è½½æå: ', file_name)24 except Exception as e:25 print('ä¸è½½å¤±è´¥: ', e)26 traceback.print_exc()27def handle_xunlei_download(url, name, suffix, xunlei_o=None):28 try:29 o = Dispatch("ThunderAgent.Agent64.1") if xunlei_o is None else xunlei_o30 valid_name = get_valid_file_name(name)31 file_suffix = get_url_suffix(url, suffix)32 file_name = get_unique_file_name(valid_name + file_suffix)33 o.AddTask(url, file_name)34 if xunlei_o is None:35 o.CommitTasks()36 print('ä¸è½½æå: ', file_name)37 except Exception as e:38 print('ä¸è½½å¤±è´¥: ', e)39 traceback.print_exc()40def handle_download_list(data_list: list[FileInfo], header=None, file_path=DOWNLOAD_PATH, **kwargs):41 if kwargs.get('xunlei', False):42 list_o = kwargs.get('o', Dispatch("ThunderAgent.Agent64.1"))43 for each_data in data_list:44 if isNull(each_data.urls):45 handle_xunlei_download(each_data.url, each_data.name, each_data.suffix, list_o)46 else:47 handle_download_index(each_data, **kwargs)48 list_o.CommitTasks()49 else:50 for each_data in data_list:51 if isNull(each_data.urls):52 handle_download_and_merag(each_data, header, file_path)53 else:54 handle_download_index(each_data, header, file_path)55def handle_download_index(data: FileInfo, header=None, file_path=DOWNLOAD_PATH, **kwargs):56 if kwargs.get('xunlei', False):57 index_o = kwargs.get('o', Dispatch("ThunderAgent.Agent64.1"))58 for index, each_url in enumerate(data.urls):59 handle_xunlei_download(each_url, data.name + get_index(data.urls, index), data.suffix, index_o)60 if kwargs.get('o') is None:61 index_o.CommitTasks()62 else:63 for index, each_url in enumerate(data.urls):64 data.name = data.name + get_index(data.urls, index)65 handle_download_and_merag(data, header, file_path)66def merge_video_audio(title, file_path=DOWNLOAD_PATH):67 audio_name = title + "_audio" + MP4_TYPE68 video_name = title + "_video" + MP4_TYPE69 command = 'ffmpeg.exe -i "{}" -i "{}" -acodec copy -vcodec copy "{}.mp4"'.format(audio_name, video_name, title)70 subprocess.check_output(command, cwd=file_path)71 os.remove(file_path + audio_name)72 os.remove(file_path + video_name)73def merge_video_pic(title, file_path=DOWNLOAD_PATH):74 video_name_no_cover = title + "_no_cover" + MP4_TYPE75 video_name = title + MP4_TYPE76 pic_name = title + "_pic" + JPG_TYPE77 os.rename(file_path + video_name, file_path + video_name_no_cover)78 command = 'ffmpeg -i "{}" -i "{}" -map 1 -map 0 -c copy -disposition:0 attached_pic "{}"'\79 .format(video_name_no_cover, pic_name, video_name)80 subprocess.check_output(command, cwd=file_path)81 os.remove(file_path + pic_name)82 os.remove(file_path + video_name_no_cover)83def handle_download_and_merag(data: FileInfo, header=None, file_path=DOWNLOAD_PATH):84 if not isNullOrBlank(data.url):85 handle_download(data.url, data.name, data.suffix, header, file_path)86 else:87 if not isNullOrBlank(data.videoInfo.audio_url):88 handle_download(data.videoInfo.video_url, data.name + "_video", MP4_TYPE, header, file_path)89 handle_download(data.videoInfo.audio_url, data.name + "_audio", MP4_TYPE, header, file_path)90 merge_video_audio(data.name, file_path)91 else:92 handle_download(data.videoInfo.video_url, data.name, MP4_TYPE, file_path)93 if not isNullOrBlank(data.videoInfo.cover_url):94 handle_download(data.videoInfo.cover_url, data.name + "_pic", JPG_TYPE, header, file_path)...
MegasharesCom.py
Source: MegasharesCom.py
...31 def setup(self):32 self.resume_download = True33 self.multiDL = self.premium34 def handle_premium(self, pyfile):35 self.handle_download(True)36 def handle_free(self, pyfile):37 if self.NO_SLOTS_PATTERN in self.data:38 self.retry(wait=5 * 60)39 m = re.search(self.REACTIVATE_PASSPORT_PATTERN, self.data)40 if m is not None:41 passport_num = m.group(1)42 request_uri = re.search(43 self.REQUEST_URI_PATTERN,44 self.data).group(1)45 random_num = re.search(46 self.REACTIVATE_NUM_PATTERN,47 self.data).group(1)48 verifyinput = self.captcha.decrypt("http://d01.megashares.com/index.php",49 get={'secgfx': "gfx", 'random_num': random_num})50 self.log_info(51 _("Reactivating passport %s: %s %s") %52 (passport_num, random_num, verifyinput))53 res = self.load("http://d01.megashares.com%s" % request_uri,54 get={'rs': "check_passport_renewal",55 'rsargs[]': verifyinput,56 'rsargs[]': random_num,57 'rsargs[]': passport_num,58 'rsargs[]': "replace_sec_pprenewal",59 'rsrnd[]': str(int(time.time() * 1000))})60 if 'Thank you for reactivating your passport' in res:61 self.captcha.correct()62 self.restart()63 else:64 self.retry_captcha(msg=_("Failed to reactivate passport"))65 m = re.search(self.PASSPORT_RENEW_PATTERN, self.data)66 if m is not None:67 time = [int(x) for x in m.groups()]68 renew = time[0] + (time[1] * 60) + (time[2] * 60)69 self.log_debug("Waiting %d seconds for a new passport" % renew)70 self.retry(wait=renew, msg=_("Passport renewal"))71 #: Check traffic left on passport72 m = re.search(self.PASSPORT_LEFT_PATTERN, self.data, re.M | re.S)73 if m is None:74 self.fail(_("Passport not found"))75 self.log_info(_("Download passport: %s") % m.group(1))76 data_left = float(m.group(2)) * \77 1024 ** {'B': 0, 'KB': 1, 'MB': 2, 'GB': 3}[m.group(3)]78 self.log_info(_("Data left: %s %s (%d MB needed)") %79 (m.group(2), m.group(3), self.pyfile.size / 1048576))80 if not data_left:81 self.retry(wait=600, msg=_("Passport renewal"))82 self.handle_download(False)83 def handle_download(self, premium=False):84 m = re.search(self.LINK_PATTERN % (1 if premium else 2), self.data)85 msg = _('%s download URL' % ('Premium' if premium else 'Free'))86 if m is None:87 self.error(msg)88 self.link = m.group(1)...
TenluaVn.py
Source: TenluaVn.py
...49 "password": bool(file_info["passwd"]),50 },51 }52 def handle_free(self, pyfile):53 self.handle_download()54 def handle_premium(self, pyfile):55 sid = self.account.info["data"]["sid"]56 self.handle_download(sid)57 def handle_download(self, sid=None):58 if self.info["tenlua"]["password"]:59 password = self.get_password()60 if password:61 file_id = self.info["pattern"]["ID"]62 args = dict(n=file_id, p=password, r=gen_r())63 if sid is not None:64 args["sid"] = sid65 password_status = self.api_request(66 "filemanager_builddownload_checkpassword", **args67 )68 if password_status["status"] == "0":69 self.fail(self._("Wrong password"))70 else:71 url = password_status["url"]...
Playwright error connection refused in docker
playwright-python advanced setup
How to select an input according to a parent sibling label
Error when installing Microsoft Playwright
Trouble waiting for changes to complete that are triggered by Python Playwright `select_option`
Capturing and Storing Request Data Using Playwright for Python
Can Playwright be used to launch a browser instance
Trouble in Clicking on Log in Google Button of Pop Up Menu Playwright Python
Scrapy Playwright get date by clicking button
React locator example
I solved my problem. In fact my docker container (frontend) is called "app" which is also domain name of fronend application. My application is running locally on http. Chromium and geko drivers force httpS connection for some domain names one of which is "app". So i have to change name for my docker container wich contains frontend application.
Check out the latest blogs from LambdaTest on this topic:
The sky’s the limit (and even beyond that) when you want to run test automation. Technology has developed so much that you can reduce time and stay more productive than you used to 10 years ago. You needn’t put up with the limitations brought to you by Selenium if that’s your go-to automation testing tool. Instead, you can pick from various test automation frameworks and tools to write effective test cases and run them successfully.
When it comes to web automation testing, there are a number of frameworks like Selenium, Cypress, PlayWright, Puppeteer, etc., that make it to the ‘preferred list’ of frameworks. The choice of test automation framework depends on a range of parameters like type, complexity, scale, along with the framework expertise available within the team. However, it’s no surprise that Selenium is still the most preferred framework among developers and QAs.
Playwright is a framework that I’ve always heard great things about but never had a chance to pick up until earlier this year. And since then, it’s become one of my favorite test automation frameworks to use when building a new automation project. It’s easy to set up, feature-packed, and one of the fastest, most reliable frameworks I’ve worked with.
The speed at which tests are executed and the “dearth of smartness” in testing are the two major problems developers and testers encounter.
With the rapidly evolving technology due to its ever-increasing demand in today’s world, Digital Security has become a major concern for the Software Industry. There are various ways through which Digital Security can be achieved, Captcha being one of them.Captcha is easy for humans to solve but hard for “bots” and other malicious software to figure out. However, Captcha has always been tricky for the testers to automate, as many of them don’t know how to handle captcha in Selenium or using any other test automation framework.
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!