How to use add_cookies method in Playwright Python

Best Python code snippet using playwright-python

test_browsercontext_add_cookies.py

Source:test_browsercontext_add_cookies.py Github

copy

Full Screen

...16import pytest17from playwright.async_api import Error18async def test_should_work(context, page, server):19 await page.goto(server.EMPTY_PAGE)20 await context.add_cookies(21 [{"url": server.EMPTY_PAGE, "name": "password", "value": "123456"}]22 )23 assert await page.evaluate("() => document.cookie") == "password=123456"24async def test_should_roundtrip_cookie(context, page, server):25 await page.goto(server.EMPTY_PAGE)26 # @see https://en.wikipedia.org/wiki/Year_2038_problem27 date = int(datetime.datetime(2038, 1, 1).timestamp() * 1000)28 document_cookie = await page.evaluate(29 """timestamp => {30 const date = new Date(timestamp);31 document.cookie = `username=John Doe;expires=${date.toUTCString()}`;32 return document.cookie;33 }""",34 date,35 )36 assert document_cookie == "username=John Doe"37 cookies = await context.cookies()38 await context.clear_cookies()39 assert await context.cookies() == []40 await context.add_cookies(cookies)41 assert await context.cookies() == cookies42async def test_should_send_cookie_header(server, context):43 cookie = []44 def handler(request):45 cookie.extend(request.requestHeaders.getRawHeaders("cookie"))46 request.finish()47 server.set_route("/empty.html", handler)48 await context.add_cookies(49 [{"url": server.EMPTY_PAGE, "name": "cookie", "value": "value"}]50 )51 page = await context.new_page()52 await page.goto(server.EMPTY_PAGE)53 assert cookie == ["cookie=value"]54async def test_should_isolate_cookies_in_browser_contexts(context, server, browser):55 another_context = await browser.new_context()56 await context.add_cookies(57 [{"url": server.EMPTY_PAGE, "name": "isolatecookie", "value": "page1value"}]58 )59 await another_context.add_cookies(60 [{"url": server.EMPTY_PAGE, "name": "isolatecookie", "value": "page2value"}]61 )62 cookies_1 = await context.cookies()63 cookies_2 = await another_context.cookies()64 assert len(cookies_1) == 165 assert len(cookies_2) == 166 assert cookies_1[0]["name"] == "isolatecookie"67 assert cookies_1[0]["value"] == "page1value"68 assert cookies_2[0]["name"] == "isolatecookie"69 assert cookies_2[0]["value"] == "page2value"70 await another_context.close()71async def test_should_isolate_session_cookies(context, server, browser):72 server.set_route(73 "/setcookie.html",74 lambda r: (75 r.setHeader("Set-Cookie", "session=value"),76 r.finish(),77 ),78 )79 page_1 = await context.new_page()80 await page_1.goto(server.PREFIX + "/setcookie.html")81 ##82 page_2 = await context.new_page()83 await page_2.goto(server.EMPTY_PAGE)84 cookies_2 = await context.cookies()85 assert len(cookies_2) == 186 assert ",".join(list(map(lambda c: c["value"], cookies_2))) == "value"87 ##88 context_b = await browser.new_context()89 page_3 = await context_b.new_page()90 await page_3.goto(server.EMPTY_PAGE)91 cookies_3 = await context_b.cookies()92 assert cookies_3 == []93 await context_b.close()94async def test_should_isolate_persistent_cookies(context, server, browser):95 server.set_route(96 "/setcookie.html",97 lambda r: (98 r.setHeader("Set-Cookie", "persistent=persistent-value; max-age=3600"),99 r.finish(),100 ),101 )102 page = await context.new_page()103 await page.goto(server.PREFIX + "/setcookie.html")104 context_1 = context105 context_2 = await browser.new_context()106 [page_1, page_2] = await asyncio.gather(context_1.new_page(), context_2.new_page())107 await asyncio.gather(page_1.goto(server.EMPTY_PAGE), page_2.goto(server.EMPTY_PAGE))108 [cookies_1, cookies_2] = await asyncio.gather(109 context_1.cookies(), context_2.cookies()110 )111 assert len(cookies_1) == 1112 assert cookies_1[0]["name"] == "persistent"113 assert cookies_1[0]["value"] == "persistent-value"114 assert len(cookies_2) == 0115 await context_2.close()116async def test_should_isolate_send_cookie_header(server, context, browser):117 cookie = []118 def handler(request):119 cookie.extend(request.requestHeaders.getRawHeaders("cookie") or [])120 request.finish()121 server.set_route("/empty.html", handler)122 await context.add_cookies(123 [{"url": server.EMPTY_PAGE, "name": "sendcookie", "value": "value"}]124 )125 page_1 = await context.new_page()126 await page_1.goto(server.EMPTY_PAGE)127 assert cookie == ["sendcookie=value"]128 cookie.clear()129 ##130 context_2 = await browser.new_context()131 page_2 = await context_2.new_page()132 await page_2.goto(server.EMPTY_PAGE)133 assert cookie == []134 await context_2.close()135async def test_should_isolate_cookies_between_launches(browser_factory, server):136 browser_1 = await browser_factory()137 context_1 = await browser_1.new_context()138 await context_1.add_cookies(139 [140 {141 "url": server.EMPTY_PAGE,142 "name": "cookie-in-context-1",143 "value": "value",144 "expires": int(datetime.datetime.now().timestamp() + 10000),145 }146 ]147 )148 await browser_1.close()149 browser_2 = await browser_factory()150 context_2 = await browser_2.new_context()151 cookies = await context_2.cookies()152 assert cookies == []153 await browser_2.close()154async def test_should_set_multiple_cookies(context, page, server):155 await page.goto(server.EMPTY_PAGE)156 await context.add_cookies(157 [158 {"url": server.EMPTY_PAGE, "name": "multiple-1", "value": "123456"},159 {"url": server.EMPTY_PAGE, "name": "multiple-2", "value": "bar"},160 ]161 )162 assert (163 await page.evaluate(164 """() => {165 const cookies = document.cookie.split(';');166 return cookies.map(cookie => cookie.trim()).sort();167 }"""168 )169 == ["multiple-1=123456", "multiple-2=bar"]170 )171async def test_should_have_expires_set_to_neg_1_for_session_cookies(context, server):172 await context.add_cookies(173 [{"url": server.EMPTY_PAGE, "name": "expires", "value": "123456"}]174 )175 cookies = await context.cookies()176 assert cookies[0]["expires"] == -1177async def test_should_set_cookie_with_reasonable_defaults(context, server):178 await context.add_cookies(179 [{"url": server.EMPTY_PAGE, "name": "defaults", "value": "123456"}]180 )181 cookies = await context.cookies()182 cookies.sort(key=lambda r: r["name"])183 assert cookies == [184 {185 "name": "defaults",186 "value": "123456",187 "domain": "localhost",188 "path": "/",189 "expires": -1,190 "httpOnly": False,191 "secure": False,192 "sameSite": "None",193 }194 ]195async def test_should_set_a_cookie_with_a_path(context, page, server):196 await page.goto(server.PREFIX + "/grid.html")197 await context.add_cookies(198 [199 {200 "domain": "localhost",201 "path": "/grid.html",202 "name": "gridcookie",203 "value": "GRID",204 }205 ]206 )207 assert await context.cookies() == [208 {209 "name": "gridcookie",210 "value": "GRID",211 "domain": "localhost",212 "path": "/grid.html",213 "expires": -1,214 "httpOnly": False,215 "secure": False,216 "sameSite": "None",217 }218 ]219 assert await page.evaluate("document.cookie") == "gridcookie=GRID"220 await page.goto(server.EMPTY_PAGE)221 assert await page.evaluate("document.cookie") == ""222 await page.goto(server.PREFIX + "/grid.html")223 assert await page.evaluate("document.cookie") == "gridcookie=GRID"224async def test_should_not_set_a_cookie_with_blank_page_url(context, server):225 with pytest.raises(Error) as exc_info:226 await context.add_cookies(227 [228 {"url": server.EMPTY_PAGE, "name": "example-cookie", "value": "best"},229 {"url": "about:blank", "name": "example-cookie-blank", "value": "best"},230 ]231 )232 assert (233 'Blank page can not have cookie "example-cookie-blank"'234 in exc_info.value.message235 )236async def test_should_not_set_a_cookie_on_a_data_url_page(context):237 with pytest.raises(Error) as exc_info:238 await context.add_cookies(239 [240 {241 "url": "data:,Hello%2C%20World!",242 "name": "example-cookie",243 "value": "best",244 }245 ]246 )247 assert (248 'Data URL page can not have cookie "example-cookie"' in exc_info.value.message249 )250async def test_should_default_to_setting_secure_cookie_for_https_websites(251 context, page, server252):253 await page.goto(server.EMPTY_PAGE)254 SECURE_URL = "https://example.com"255 await context.add_cookies([{"url": SECURE_URL, "name": "foo", "value": "bar"}])256 [cookie] = await context.cookies(SECURE_URL)257 assert cookie["secure"]258async def test_should_be_able_to_set_unsecure_cookie_for_http_website(259 context, page, server260):261 await page.goto(server.EMPTY_PAGE)262 HTTP_URL = "http://example.com"263 await context.add_cookies([{"url": HTTP_URL, "name": "foo", "value": "bar"}])264 [cookie] = await context.cookies(HTTP_URL)265 assert not cookie["secure"]266async def test_should_set_a_cookie_on_a_different_domain(context, page, server):267 await page.goto(server.EMPTY_PAGE)268 await context.add_cookies(269 [{"url": "https://www.example.com", "name": "example-cookie", "value": "best"}]270 )271 assert await page.evaluate("document.cookie") == ""272 assert await context.cookies("https://www.example.com") == [273 {274 "name": "example-cookie",275 "value": "best",276 "domain": "www.example.com",277 "path": "/",278 "expires": -1,279 "httpOnly": False,280 "secure": True,281 "sameSite": "None",282 }283 ]284async def test_should_set_cookies_for_a_frame(context, page, server):285 await page.goto(server.EMPTY_PAGE)286 await context.add_cookies(287 [{"url": server.PREFIX, "name": "frame-cookie", "value": "value"}]288 )289 await page.evaluate(290 """src => {291 let fulfill;292 const promise = new Promise(x => fulfill = x);293 const iframe = document.createElement('iframe');294 document.body.appendChild(iframe);295 iframe.onload = fulfill;296 iframe.src = src;297 return promise;298 }""",299 server.PREFIX + "/grid.html",300 )...

Full Screen

Full Screen

parser.py

Source:parser.py Github

copy

Full Screen

1import json2import csv3from time import sleep4from selenium.common.exceptions import TimeoutException5from selenium.webdriver.common.keys import Keys6from bs4 import BeautifulSoup as bs7from openpyxl import load_workbook8import requests9from browser import Browser10class Parser:11 current_position = list()12 current_position.append([13 'Talent',14 'Recruiter',15 'Recruitment',16 'Recruiting',17 'Sourcing',18 'Sourcer'])19 current_position.append([20 'people',21 'HR',22 'human'23 ])24 current_position.append([25 'Operations',26 'Assistant',27 'Office'28 ])29 current_position.append([30 'COO',31 'CEO',32 'Founder',33 'Co-Founder'34 ])35 RUCAPTCHA_KEY = "################"36 add_input_script = """37 var inp = document.createElement('input');38 inp.type = 'submit';39 inp.value = 'send';40 inp.id = 'send_token';41 document.getElementById('captcha-form').appendChild(inp);42 """43 def __init__(self, **kwargs):44 self.parser = Browser(**kwargs)45 self.parser.browser.get('https://www.google.com.ua/')46 def solve_recaptcha(self):47 self.parser.browser.execute_script(self.add_input_script)48 send_token_input = self.parser.browser.find_element_by_id('send_token')49 text_area_for_token = self.parser.browser.find_element_by_id('g-recaptcha-response')50 self.parser.browser.execute_script("document.getElementById('g-recaptcha-response').style.display = 'inline';")51 cookies = self.parser.browser.get_cookies()52 cookies_to_send = str()53 for cookie in cookies:54 # print(cookie)55 for key in cookie.keys():56 cookies_to_send += f"{key}:{cookie[key]};"57 html = self.parser.browser.page_source58 bs_obj = bs(html, 'html5lib')59 recaptca_tag = bs_obj.find('div', {'class': 'g-recaptcha', 'id': 'recaptcha'})60 data_sitekey = recaptca_tag['data-sitekey']61 data_s = recaptca_tag['data-s']62 data_callback = recaptca_tag['data-callback']63 page_url = self.parser.browser.current_url64 req_str = f"https://rucaptcha.com/in.php?" \65 f"key={self.RUCAPTCHA_KEY}&" \66 f"method=userrecaptcha&" \67 f"googlekey={data_sitekey}&" \68 f"data-s={data_s}&" \69 f"cookies={cookies_to_send}&" \70 f"pageurl={page_url}&" \71 f"json=1&" \72 f"debug_dumps=1"73 # if we want to use proxy, we should use this request url74 '''75 req_str = f"https://rucaptcha.com/in.php?" \76 f"key={RUCAPTCHA_KEY}&" \77 f"method=userrecaptcha&" \78 f"googlekey={data_sitekey}&" \79 f"data-s={data_s}&" \80 f"proxy={AUTH}@{PROXY}&" \81 f"proxytype=HTTPS&" \82 f"pageurl={page_url}&" \83 f"json=1&" \84 f"debug_dumps=1"85 '''86 req_ans = requests.get(req_str)87 response = req_ans.text88 response = json.loads(response)89 if response['status'] == 1:90 id = response['request']91 req_res = f"https://rucaptcha.com/res.php?" \92 f"key={RUCAPTCHA_KEY}&" \93 f"action=get&" \94 f"id={id}&" \95 f"json=1"96 print("Our request is processing")97 print(f"id = {id}")98 while True:99 sleep(20)100 res = requests.get(req_res).text101 res = json.loads(res)102 if res['status'] == 1:103 print("Captcha is solved successfully")104 token = res['request']105 add_cookies = res['cookies']106 for key in add_cookies.keys():107 if add_cookies[key] == 'True':108 add_cookies[key] = True109 continue110 if add_cookies[key] == 'False':111 add_cookies[key] = False112 continue113 if add_cookies[key].isdigit():114 add_cookies[key] = int(add_cookies[key])115 text_area_for_token.send_keys(token)116 send_token_input.click()117 return True118 if res['request'] == 'ERROR_CAPTCHA_UNSOLVABLE':119 self.parser.browser.refresh()120 self.solve_recaptcha()121 break122 print(f"{res['request']} -- Waiting")123 def check_current_position(self, title):124 for cur_pos in self.current_position:125 for pos in cur_pos:126 if pos in title:127 return True128 return False129 def get_google_search_res(self, query):130 search_box = self.parser.browser.find_element_by_name('q')131 search_box.send_keys(Keys.CONTROL + 'a')132 search_box.send_keys(Keys.DELETE)133 search_box.send_keys(query)134 sleep(2)135 search_box.submit()136 sleep(2)137 try:138 search_com = self.parser.interaction_with('//div[@class="g"]/div/div/div[2]')139 except TimeoutException:140 self.solve_recaptcha()141 print('hey', [i.text.split('\n')[0].split(' · ‎')[-1] for i in search_com])142 search_div = self.parser.interaction_with('//div[@class="g"]')143 res = []144 if not search_div:145 self.solve_recaptcha()146 for element, com in zip(search_div, search_com):147 html = element.get_attribute('innerHTML')148 soup = bs(html, 'html5lib')149 h3 = soup.h3.get_text()150 splitted_h3 = h3.split(' - ')151 if len(splitted_h3) == 1:152 another_split = h3.split(' – ')[0]153 if len(another_split) == 1:154 continue155 name = another_split[0]156 print(name)157 job_title = another_split[1]158 else:159 name = splitted_h3[0]160 job_title = splitted_h3[1]161 print(job_title)162 # если у нас нет текущих слов в job title163 # то пропускаем164 if not self.check_current_position(job_title):165 return None166 if 'href' in soup.a.attrs:167 link = soup.a['href']168 num = search_div.index(element) + 1169 res.append({'name': name, 'title': job_title,170 'link': link, 'num': num,171 'comp_from_google': com172 })173 return res174 def get_comp_title(self, url):175 linkedin_browser = Browser(gui=True, profile='linkedin')176 linkedin_browser.browser.get(url)177 try:178 name = linkedin_browser.interaction_with('//a[@class="pv-top-card--experience-list-item"]')[0].text.strip()179 except TypeError:180 name = linkedin_browser.interaction_with('//a[@class="pv-top-card--experience-list-item"]').text.strip()181 linkedin_browser.browser.quit()182 return name183 def find_names(self, names_list):184 with open('res_names.csv', 'a') as csv_file:185 fieldnames = [186 'name', 'title', 'num', 'comp_from_google',187 'comp_title', 'link', 'word'188 ]189 writer = csv.DictWriter(csv_file, fieldnames=fieldnames)190 writer.writeheader()191 for comp_title in names_list:192 cur_pos_str = '" OR "'.join(self.current_position[0])193 cur_pos_str = f'"{cur_pos_str}"'194 query = f'(intitle:"{comp_title}") (intitle:{cur_pos_str}) site:linkedin.com/in/'195 google_res = self.get_google_search_res(query)196 if google_res:197 for res in google_res:198 url = res['link']199 res['word'] = query200 res['comp_titles'] = self.get_comp_title(url)...

Full Screen

Full Screen

main.py

Source:main.py Github

copy

Full Screen

1from selenium.webdriver import ChromeOptions, Chrome2from selenium.webdriver.common.keys import Keys3from bs4 import BeautifulSoup4from time import sleep5import requests6from random import randint7import json8current_position = list()9current_position.append([10 'Talent',11 'Recruiter',12 'Recruitment',13 'Recruiting',14 'Sourcing',15 'Sourcer'])16current_position.append([17 'people',18 'HR',19 'human'20])21current_position.append([22 'Operations',23 'Assistant',24 'Office'25])26current_position.append([27 'COO',28 'CEO',29 'Founder',30 'Co-Founder'31])32RUCAPTCHA_KEY = "c76bbefa8876305065858bb538932ae0"33add_input_script = """34var inp = document.createElement('input');35inp.type = 'submit';36inp.value = 'send';37inp.id = 'send_token';38document.getElementById('captcha-form').appendChild(inp);39"""40def solve_recaptcha(browser):41 browser.execute_script(add_input_script)42 send_token_input = browser.find_element_by_id('send_token')43 text_area_for_token = browser.find_element_by_id('g-recaptcha-response')44 browser.execute_script("document.getElementById('g-recaptcha-response').style.display = 'inline';")45 cookies = browser.get_cookies()46 cookies_to_send = str()47 for cookie in cookies:48 # print(cookie)49 for key in cookie.keys():50 cookies_to_send += f"{key}:{cookie[key]};"51 html = browser.page_source52 bs_obj = BeautifulSoup(html, 'html5lib')53 recaptca_tag = bs_obj.find('div', {'class': 'g-recaptcha', 'id': 'recaptcha'})54 data_sitekey = recaptca_tag['data-sitekey']55 data_s = recaptca_tag['data-s']56 data_callback = recaptca_tag['data-callback']57 page_url = browser.current_url58 req_str = f"https://rucaptcha.com/in.php?" \59 f"key={RUCAPTCHA_KEY}&" \60 f"method=userrecaptcha&" \61 f"googlekey={data_sitekey}&" \62 f"data-s={data_s}&" \63 f"cookies={cookies_to_send}&" \64 f"pageurl={page_url}&" \65 f"json=1&" \66 f"debug_dumps=1"67 # if we want to use proxy, we should use this request url68 '''69 req_str = f"https://rucaptcha.com/in.php?" \70 f"key={RUCAPTCHA_KEY}&" \71 f"method=userrecaptcha&" \72 f"googlekey={data_sitekey}&" \73 f"data-s={data_s}&" \74 f"proxy={AUTH}@{PROXY}&" \75 f"proxytype=HTTPS&" \76 f"pageurl={page_url}&" \77 f"json=1&" \78 f"debug_dumps=1"79 '''80 req_ans = requests.get(req_str)81 response = req_ans.text82 response = json.loads(response)83 if response['status'] == 1:84 id = response['request']85 req_res = f"https://rucaptcha.com/res.php?" \86 f"key={RUCAPTCHA_KEY}&" \87 f"action=get&" \88 f"id={id}&" \89 f"json=1"90 print("Our request is processing")91 print(f"id = {id}")92 while True:93 sleep(20)94 res = requests.get(req_res).text95 res = json.loads(res)96 if res['status'] == 1:97 print("Captcha is solved successfully")98 token = res['request']99 add_cookies = res['cookies']100 for key in add_cookies.keys():101 if add_cookies[key] == 'True':102 add_cookies[key] = True103 continue104 if add_cookies[key] == 'False':105 add_cookies[key] = False106 continue107 if add_cookies[key].isdigit():108 add_cookies[key] = int(add_cookies[key])109 text_area_for_token.send_keys(token)110 send_token_input.click()111 return True112 if res['request'] == 'ERROR_CAPTCHA_UNSOLVABLE':113 browser.refresh()114 solve_recaptcha(browser)115 break116 print(f"{res['request']} -- Waiting")117def check_current_position(title):118 for cur_pos in current_position:119 for pos in cur_pos:120 if pos in title:121 return True122 return False123def find_in_text(text):124 text = text.lower()125 for word in current_position[0]:126 if text.find(word.lower()) != -1:127 return word128def get_google_search_res(browser, query):129 search_box = browser.find_element_by_name('q')130 search_box.send_keys(Keys.CONTROL + 'a')131 search_box.send_keys(Keys.DELETE)132 search_box.send_keys(query)133 sleep(2)134 search_box.submit()135 sleep(2)136 scroll = randint(350, 450)137 browser.execute_script(f'window.scrollTo(0,{scroll});')138 sleep(randint(2, 7))139 html = browser.page_source140 bs_obj = BeautifulSoup(html, 'html5lib')141 res_tag = bs_obj.find('div', {'id': 'res'})142 while True:143 if not res_tag:144 #solve_recaptcha(browser)145 sleep(20)146 html = browser.page_source147 bs_obj = BeautifulSoup(html, 'html5lib')148 res_tag = bs_obj.find('div', {'id': 'res'})149 else:150 res_tags = res_tag.find_all('div', {'class': 'g'})151 break152 res = list()153 position = 0154 for res_tag in res_tags:155 position += 1156 h3 = res_tag.h3.get_text()157 text = str(res_tag.select('span > span'))158 splitted_h3 = h3.split(' - ')159 if len(splitted_h3) == 1:160 another_split = h3.split(' – ')[0]161 if len(another_split) == 1:162 continue163 name = another_split[0]164 job_title = another_split[1]165 company_title = None166 elif len(splitted_h3) == 2:167 name = splitted_h3[0]168 job_title = splitted_h3[1]169 company_title = None170 else:171 name = splitted_h3[0]172 job_title = splitted_h3[1]173 company_title = splitted_h3[2].split('|')[0]174 # если у нас нет текущих слов в job title175 # то пропускаем176 if not check_current_position(job_title):177 continue178 link = ''179 if 'href' in res_tag.a.attrs:180 link = res_tag.a['href']181 res.append({'name': name,182 'title': job_title,183 'link': link,184 'company_title': company_title,185 'match': find_in_text(text),186 'position': position187 })188 return res189def init_driver(path_driver):190 chrome_options = ChromeOptions()191 # chrome_options.add_argument("--headless")192 chrome_options.add_argument("--window-size=1920,1080")193 user_agent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36"194 chrome_options.add_argument(f'user-agent={user_agent}')195 driver = Chrome(executable_path=path_driver, options=chrome_options)196 return driver197def find_names():198 with open('parsed_names.txt', 'r') as f:199 lines = f.read().split('\n')200 browser = init_driver('./chromedriver')201 browser.get('https://www.google.com')202 counter = 1203 for line in lines:204 comp_title = line205 print(f"{counter} -- {comp_title}")206 cur_pos_str = '" OR "'.join(current_position[0])207 cur_pos_str = f'"{cur_pos_str}"'208 query = f'(intitle:"{comp_title}") (intitle:{cur_pos_str}) site:linkedin.com/in/'209 res = get_google_search_res(browser, query)210 for r in res:211 print(r)212 with open('res_names.csv', 'a') as f:213 f.write(f"{r['name']};{r['title']};{r['link']};{comp_title};{r['company_title']};{r['match']};{r['position']}\n")214 counter += 1215 sleep(2)216if __name__ == "__main__":217 # comp_titles()...

Full Screen

Full Screen

spider.py

Source:spider.py Github

copy

Full Screen

...95 Rule(post_extract, follow=True, callback='parse_post', process_request='add_cookies'),96 Rule(follow_extract, follow=True, callback='parse_follow', process_request='add_cookies'),97 # Rule(follow_extract, follow=True, process_request='add_cookies'),98 )99 def add_cookies(self, request):100 request.replace(cookies=self.cookies)101 return request102 #103 a_count = 0104 p_count = 0105 f_count = 0106 g_count = 0107 fa_count = 0108 def parse_author(self, response):109 # self.a_count += 1110 # print('author: ', self.a_count, ' ', response.url)111 author_item = get_author_item(response)112 # 获取粉丝和关注列表113 fans_url = get_fans_page_url(response)...

Full Screen

Full Screen

Playwright tutorial

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.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Python 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