File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,10 @@ uv run scripts/save_context.py
6060uv run scripts/load_context.py
6161```
6262
63+ ### Development
64+
65+ - [ Web Scraping Google Maps Using Playwright Python And OpenAI API] ( https://www.youtube.com/watch?v=6WxaEbkOPKM )
66+
6367## [ Microsoft Playwright Testing] ( https://learn.microsoft.com/ja-jp/azure/playwright-testing/ )
6468
6569- [ Get Started Sample] ( https://github.com/microsoft/playwright-testing-service/tree/main/samples/get-started )
Original file line number Diff line number Diff line change 1+ import time
2+
3+ from playwright .sync_api import sync_playwright
4+
5+ base_url = "https://maps.google.com"
6+ search_query = "蕎麦屋 京都駅"
7+
8+ playwright = sync_playwright ().start ()
9+ browser = playwright .chromium .launch (headless = False )
10+ context = browser .new_context (
11+ java_script_enabled = True ,
12+ locale = "ja-JP" ,
13+ )
14+ page = context .new_page ()
15+ page .goto (base_url , wait_until = "load" )
16+
17+ # find the search box
18+ input_box = page .locator ('//input[@name="q"]' )
19+ input_box .fill (search_query )
20+ input_box .press ("Enter" )
21+
22+ xpath_search_result_element = '//div[@role="feed"]'
23+ page .wait_for_selector (xpath_search_result_element )
24+ results_container = page .query_selector (xpath_search_result_element )
25+ results_container .scroll_into_view_if_needed ()
26+
27+ keep_scrolling = True
28+ while keep_scrolling :
29+ results_container .press ("Space" )
30+ time .sleep (2.5 )
31+
32+ # "リストの最後に到達しました。" という文字列を含む要素があるか確認
33+ if results_container .query_selector ('//span[contains(text(), "リストの最後に到達しました。")]' ):
34+ results_container .press ("Space" )
35+ keep_scrolling = False
36+
37+ with open ("maps.html" , "w" , encoding = "utf-8" ) as f :
38+ f .write (results_container .inner_html ())
39+
40+ context .close ()
41+ browser .close ()
42+ playwright .stop ()
You can’t perform that action at this time.
0 commit comments