JavaScript
x
51
51
1
import time
2
from playwright.sync_api import sync_playwright
3
import pandas as pd
4
5
with sync_playwright() as p:
6
browser = p.webkit.launch(headless=False)
7
baseurl = "https://www.ifep.ro/justice/lawyers/lawyerspanel.aspx"
8
page = browser.new_page()
9
page.goto(baseurl)
10
productlinks = []
11
for k in range(1, 2450):
12
links = page.query_selector_all("//div[@class='list-group']//a")
13
for link in links:
14
link_href = link.get_attribute("href")
15
if link_href.startswith("LawyerFile.aspx"):
16
productlinks.append("https://www.ifep.ro/justice/lawyers/" + link_href)
17
18
dropdown=page.wait_for_selector("#MainContent_ddlRecords")
19
dropdown.selectOption({"label": "30"})
20
time.sleep(5)
21
page.wait_for_selector("#MainContent_PagerTop_NavNext").click()
22
time.sleep(2) # wait for load the page
23
data=[]
24
for product in productlinks:
25
wev={}
26
page.goto(product)
27
title = page.wait_for_selector('#HeadingContent_lblTitle').text_content()
28
wev['title']=title
29
d1 = page.wait_for_selector("//div[@class='col-md-10']//p[1]").text_content()
30
d1 = d1.strip().split()[-1]
31
d6=page.wait_for_selector("//span[@class='text-nowrap']//a").text_content()
32
wev['Email']=d6
33
d5 = page.wait_for_selector("//span[@class='padding-right-md text-primary']").text_content()
34
d5=d5.replace(".", "")
35
wev['phone']=d5
36
wev['Avocat Definitiv']=d1
37
d2 = page.wait_for_selector("//div[@class='col-md-10']//p[2]").text_content()
38
d2 = d2.strip().split()[-1]
39
wev['Dată înscriere']=d2
40
d3 = page.wait_for_selector("//div[@class='col-md-10']//p[3]//span").text_content()
41
d3 = d3.strip().split()[-1]
42
wev['Situaţie curentă în tablou']=d3
43
d4 = page.wait_for_selector("//div[@class='col-md-10']//p[4]").text_content()
44
d4 = d4.strip().split()[-1]
45
wev['Instanţe cu drept de concluzii']=d4
46
data.append(wev)
47
48
df=pd.DataFrame(data)
49
df.to_csv("test.csv")
50
browser.close()
51
I want to click these option on the pages is there any I am new to a playwright I am not familiar with playwrights so much kindly any solution recommended these is page link https://www.ifep.ro/justice/lawyers/lawyerspanel.aspx
Advertisement
Answer
You can use the select_options for selecting 30
.
JavaScript
1
2
1
page.select_option('select#MainContent_ddlRecords', '30')
2
You can use the text selector and then click the checkboxes like this:
JavaScript
1
2
1
page.locator("text=Tabloul avocaţilor stagiari").click()
2