How to use all_inner_texts method in Playwright Python

Best Python code snippet using playwright-python

pw_getHisDataJ_test3.py

Source:pw_getHisDataJ_test3.py Github

copy

Full Screen

...49 # 그리고, 첫번째트리구조에선 g 에 코인이름이 들어있고 두번째트리구조에선 i 에 코인이름이 들어있다고 하면, '~~ X Y Z' 형태의 셀렉터로 Z는 두 구조의 Z 모두 찾아지지만, (여기서 내가 '구조'라고 하는건 전체 트리의 일부를 얘기하는것임.) 50 # 코인이름을 가져오기위해 이 셀렉터의 뒤에 ' f g' 를 붙여서 '~~ X Y Z f g' 셀렉터를 쓰면 트리경로1에 매칭되는 코인이름(을가진엘리먼트)들만 찾아지는거지. 51 # '~~ X Y Z i' 셀렉터를 쓰면 트리경로2의 코인이름(을가진엘리먼트)들만 찾아지는거고. 52 # 따라서, 마우스휠스크롤 아래로 내리지 않아도, 그냥 두가지 셀렉터를 사용하면 한페이지의 100개 코인이름들을 전부 다 가져올 수 있는거지. 53 coinCMCnames_inViewport = await page.locator('tr td a[href*="/currencies/"][href$="/"]:not([href$="/markets/"]):not([href$="/airdrop/"]) >div>div>p').all_inner_texts() 54 coinCMCtickers_inViewport = await page.locator('tr td a[href*="/currencies/"][href$="/"]:not([href$="/markets/"]):not([href$="/airdrop/"]) >div>div>div>p').all_inner_texts() 55 coinCMCnames_outViewport = await page.locator('tr td a[href*="/currencies/"][href$="/"]:not([href$="/markets/"]):not([href$="/airdrop/"]) > :nth-child(2)').all_inner_texts()56 coinCMCtickers_outViewport = await page.locator('tr td a[href*="/currencies/"][href$="/"]:not([href$="/markets/"]):not([href$="/airdrop/"]) > :nth-child(3)').all_inner_texts()57 coinCMCnames_oneP = coinCMCnames_inViewport + coinCMCnames_outViewport 58 coinCMCtickers_oneP = coinCMCtickers_inViewport + coinCMCtickers_outViewport 59 assert len(coinCMCnames_oneP)==len(set(coinCMCnames_oneP))==len(coinCMCtickers_oneP)==len(set(coinCMCtickers_oneP)) == 100 60 coinCMCnameTickerTups_oneP = list(zip(coinCMCnames_oneP, coinCMCtickers_oneP)) 61 nameTickerTup2coinUrl_oneP = {nameTickerTup: coinUrl for (nameTickerTup, coinUrl) in zip(coinCMCnameTickerTups_oneP, urls_oneP)} 62 # print(f'j) 코인CMC(이름,티커)들 {len(coinCMCnameTickerTups_oneP)}개: {coinCMCnameTickerTups_oneP}\n') 63 print(f'j) {pageUrl}의 코인CMC(이름,티커)->코인url 맵 (코인 {len(nameTickerTup2coinUrl_oneP)}개): {nameTickerTup2coinUrl_oneP}\n') 64 65 66 # await page.mouse.wheel(0, 9000) 67 # # await page.wait_for_timeout(2500) 68 # coinCMCnames_loc = page.locator('tr td a[href*="/currencies/"][href$="/"]:not([href$="/markets/"]):not([href$="/airdrop/"])') # 일단 스크롤 맨밑까지 내리고 이거 쓰면 코인CMC이름이 포함돼서 나오긴 한다!!! /21.12.14.2:28. 69 # # coinCMCnames_loc = page.locator('tr td a[href*="/currencies/"][href$="/"]:not([href$="/markets/"])>div>div>p') 70 # # coinCMCnames_loc = page.locator('tbody>tr>td>div>a>div>div>p') 71 # print(f'j) coinCMCnames_loc.count(): {await coinCMCnames_loc.count()}') 72 # all_inner_texts = await coinCMCnames_loc.all_inner_texts()73 # print(f'\nj) {pageUrl}의 all_inner_texts {len(all_inner_texts)}개: {all_inner_texts}')74 # all_text_contents = await coinCMCnames_loc.all_text_contents() 75 # print(f'\nj) {pageUrl}의 all_text_contents {len(all_text_contents)}개: {all_text_contents}') 76 77 # coinCMCnames_oneP = await coinCMCnames_loc.evaluate_all('selecteds=>selecteds.map(e=>e.innerText)') 78 # # print(f'j) {pageUrl} 의 코인CMC이름들 {len(coinCMCnames_oneP)}개: {coinCMCnames_oneP}\n') 79 return urls_oneP, coinCMCnames_oneP 80 # TODO TODO TODO 메인화면의 코인명, url의 코인명 둘다 가져와서 맵핑해놓는게 좋을듯. /21.12.12.13:48. 81 82 # TODO TODO TODO 맨마지막 딱 한개 코인 {'https://coinmarketcap.com/currencies/apenft/'} 때문에 계~~~속 while문 도네;;; 뭐지?? 83 # 혹시 마우스로 다음페이지 클릭하는거랑 달리, url로 바로 다음페이지로 넘어가면 뭐 다른가??? /21.12.12.23:24. 84 # 조사대상 코인들 url 가져옴. 85 while True: # 혹시나 한페이지(100개코인)단위로 가져오는도중 시총순위 달라져서 중복되는코인 생길경우, 첫페이지부터 다시 시작. /21.12.12.16:26. 86 coinUrls = []...

Full Screen

Full Screen

pw_getHisDataJ_test.py

Source:pw_getHisDataJ_test.py Github

copy

Full Screen

...32 # 이제 특정 코인의 n일치 시세데이터가 모두 웹페이지에 보이는 상황임. 지금은 1년치로 해줬고. 33 tableRows_loc = page.locator('table.cmc-table tbody tr') 34 # print(f'j) type tableRows_loc: {type(tableRows_loc)}') # <class 'playwright.async_api._generated.Locator'> 35 print(f'j) tableRows_loc.count(): {await tableRows_loc.count()}') 36 # print(f'j) tableRows_loc.all_inner_texts(): {await tableRows_loc.all_inner_texts()}') 37 38 # 걍 모든 td들을 선택한 locator로 all_inner_texts 해주고나서 각 row 별로 묶어줘도 되지만, 혹시나 순서가 제대로 안되거나 할까봐 이렇게 row별로 해줘봄. /21.12.2.13:08. 39 table_vals = await tableRows_loc.evaluate_all(40 """41 trs=>trs.map(42 tr => Array.from(tr.childNodes).map(td=>td.innerText) 43 ) 44 """45 )46 print(f'j) len table_vals: {len(table_vals)}') 47 print(f'j) table_vals: {table_vals}') 48 # # 그냥 한번 해본 부분. 49 # # 모든 td들 선택해서 row별로 묶은뒤에 윗값이랑 똑같은지 비교해봄. /21.12.2.13:12. 50 # tableCells_loc = page.locator('table.cmc-table tbody tr td') # 모든 td 들. 좌->우, 상->하 순서대로인듯? /21.12.2.12:43. 51 # print(f'j) tableCells_loc.count(): {await tableCells_loc.count()}') 52 # tableCells = await tableCells_loc.all_inner_texts() 53 # table_vals2 = []54 # row = []55 # for i, e in enumerate(tableCells):56 # row.append(e) 57 # if (i+1)%7 == 0: 58 # table_vals2.append(row) 59 # row = [] 60 # print(f'\nj) len table_vals2: {len(table_vals2)}') 61 # print(f'j) table_vals2: {table_vals2}') 62 # # table_vals 랑 table_vals2 랑 값들 및 순서 완전히 똑같은지 함 확인해봄. /21.12.2.13:28. 63 # for (row1, row2) in zip(table_vals, table_vals2): 64 # for (e1, e2) in zip(row1, row2):65 # if e1!=e2:66 # raise ValueError(f'j) Error!!! 값이 일치해야하는데 다름!!! {e1} != {e2}') ...

Full Screen

Full Screen

subito.py

Source:subito.py Github

copy

Full Screen

...35 for t in typology:36 house_links[m] = {swap_dict(typology_map['subito'])[t]: []}37 try:38 page.goto(f"https://www.subito.it/annunci-sicilia/vendita/{t}/catania/{m}")39 navs_txt = ' '.join(page.locator("nav").all_inner_texts())40 max_page = max([int(n) for n in re.findall(r"(\d+)", navs_txt)])41 except:42 max_page = 143 for page_n in range(1, max_page+1):44 page.goto(f"https://www.subito.it/annunci-sicilia/vendita/{t}/catania/{m}/?o={page_n}",45 wait_until='domcontentloaded', timeout=30*1000)46 houses_html = page.locator('.items').first.inner_html()47 soup = BeautifulSoup(houses_html, 'html.parser')48 house_links[m][swap_dict(typology_map['subito'])[t]].extend([l['href'] for l in soup.find_all('a', href=True)49 if urlparse(l['href']).path.startswith('/'+t)])50 print(house_links.keys())51 page.close()52 context.close()53 houses = []54 for m in house_links.keys():55 for t in house_links[m].keys():56 hl_stacks = np.array_split(house_links[m][t], ceil(len(house_links[m][t])/250))57 for hl_stack in hl_stacks:58 context = open_context(browser, trace)59 for link in tqdm(hl_stack, total=len(hl_stack)):60 page = context.new_page()61 page.route(re.compile(r"(\.png$)|(\.jpg$)"), lambda route: route.abort())62 page.goto(link, wait_until='domcontentloaded')63 title = page.locator('h1').first.inner_text()64 surface = page.locator("text=/\d+ mq/").first.inner_text()65 description = page.locator('p:below(:text("Descrizione"))').first.inner_text()66 index = int(re.findall(r"(\d+)", page.url)[-1])67 house = House(index, 'subito', link, t, m, title, surface, description)68 69 if page.is_visible("span:has-text('€')"):70 price = page.locator("span:has-text('€')").first.inner_text()71 house.price = price72 else:73 house.price = ''74 if page.is_visible('span:right-of(:text("Piano"))'):75 ait = ' '.join(page.locator('span:right-of(:text("Piano"))').all_inner_texts())76 house.floor = re.findall(r"\d{1}", ait)[0]77 else:78 house.floor = ''79 80 if page.is_visible('span:right-of(:text("Locali"))'):81 ait = ' '.join(page.locator('span:right-of(:text("Locali"))').all_inner_texts())82 house.rooms = re.findall(r"\d{1,2}", ait)[0]83 else:84 house.rooms = ''85 houses.append(house)86 page.close()87 context.close()88 df = pd.DataFrame(houses)89 df.to_csv("house.csv", index=False)90 print(df)91 houses = SubitoHouses(df)92 houses.preprocess()93 houses.dump(pd.Timestamp.now().strftime("%Y-%m-%d"))...

Full Screen

Full Screen

pw_getHisDataJ_test4.py

Source:pw_getHisDataJ_test4.py Github

copy

Full Screen

...24 print(f'j) {pageUrl} 의 각 코인 url들 총 {len(urls_oneP)}개 찾음. (100개여야함)') 25 # assert (await coinUrls_loc.count()) == len(urls_oneP) == 100, f'j) {pageUrl} 의 각 코인 url이 {len(urls_oneP)}개임!!! (100개여야하는데.)' 26 27 # # (코인CMC이름, 티커) 튜플의 리스트 만듦. 나중에 코인CMC이름<->코인url이름 맵핑 위해. /21.12.14.22:33. 28 # coinCMCnames_inViewport = await page.locator('tr td a[href*="/currencies/"][href$="/"]:not([href$="/markets/"]):not([href$="/airdrop/"]) >div>div>p').all_inner_texts() 29 # coinCMCtickers_inViewport = await page.locator('tr td a[href*="/currencies/"][href$="/"]:not([href$="/markets/"]):not([href$="/airdrop/"]) >div>div>div>p').all_inner_texts() 30 # coinCMCnames_outViewport = await page.locator('tr td a[href*="/currencies/"][href$="/"]:not([href$="/markets/"]):not([href$="/airdrop/"]) > :nth-child(2)').all_inner_texts()31 # coinCMCtickers_outViewport = await page.locator('tr td a[href*="/currencies/"][href$="/"]:not([href$="/markets/"]):not([href$="/airdrop/"]) > :nth-child(3)').all_inner_texts()32 # coinCMCnames_oneP = coinCMCnames_inViewport + coinCMCnames_outViewport # 더해주는 순서 중요. /21.12.14.20:10. 33 # coinCMCtickers_oneP = coinCMCtickers_inViewport + coinCMCtickers_outViewport 34 # assert len(coinCMCnames_oneP)==len(set(coinCMCnames_oneP))==len(coinCMCtickers_oneP)==len(set(coinCMCtickers_oneP)) == 100 35 # coinCMCnameTickerTups_oneP = list(zip(coinCMCnames_oneP, coinCMCtickers_oneP)) # [('Bitcoin', 'BTC), ('Ethereum', 'ETH'), ...] 36 # # print(f'j) 코인CMC(이름,티커)들 {len(coinCMCnameTickerTups_oneP)}개: {coinCMCnameTickerTups_oneP}\n') 37 38import time 39t1 = time.time()...

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