簡體   English   中英

如何提取帶有經度和緯度的位置名稱? 使用 python 和 selenium

[英]How to extract location name with longitude and latitude? Using python and selenium

檢查網絡屏幕截圖

網址鏈接: https://www.yes.com.kh/support/find-shop

我現在的代碼只是設法傳輸位置名稱。 由於代碼在 .network 文件中,因此很難獲得經度和緯度。 有什么想法嗎? 這太難了。

 #situation: -no elements in page source
 # - use inspect to find the page source
 # - in the same div class 

import selenium 
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from webdriver_manager.chrome import ChromeDriverManager
#from selenium.webdriver.common.keys import Keys
import pandas as pd

#install a webdriver
driver = webdriver.Chrome(ChromeDriverManager().install())

#input link for the web driver to access
driver.get('https://www.yes.com.kh/support/find-shop')

locations=WebDriverWait(driver,20).until(EC.presence_of_all_elements_located((By.XPATH,'//div[@class="item blog"]//div[@class="d-title"]')))

這是我的 output。它只是設法捕獲網站上的所有數據,但當您嘗試在列出的所有省份加載更多時,還有其他數據。

                                   Location Name
0                            Tit Heng Phone Shop
1                               Nina2 Phone Shop
2                                 G B Phone Shop
3                             Rathana Phone Shop
4                    Chet Traprek Hou Phone Shop
5                            Siv Heng Phone Shop
6                                D Na Phone Shop
7                       Heang Heang 2 Phone Shop
8                              Rayuth Phone Shop
9                               Virak Phone Shop
10                         yes hub Sihanoukville
11  yes hub Sihanouk Ville International Airport
12                                  Kim Nai Houy
13                          Kim Sreng phone shop
14                                   Por Sokleng
15                            yes hub Battambang
16                       Yorn Kim Err Phone Shop
17                                   Yorn Bunyan
18                           Yon Hour Phone Shop
19                           Yin Fuoy Phone Shop
20                                yes hub Poipet
21                        yes hub Serei Sorphorn
22                                    Sam Sophea
23                                 Kheang Lyhour
24                                   Rith Sovann
25                             yes hub siem reap
26       yes hub Siem Reap International Airport
27                            Vannak Phone Shopp
28                           Rattanak Phone Shop
29                          Hun Rithy Phone Shop
30                                   yes hub kep
31                                 yes hub takeo
32                          yes hub kampong speu
33                       Khoun Phalla Phone Shop
34                          Pheng Nai phone shop
35                     Pheng Chhunleng phon shop
36                       Cheang Srong phone shop
37                                yes hub Kampot
38                                Thov Vannarith
39                                Preap Samphors
40                          yes hub kampong cham
41                         Pea Vibuth Phone shop
42                       Oeng Sopanha Phone Shop
43                          Sorn Naro phone shop
44                         Ka tangkea phone shop
45                                yes hub pursat
46                            yes hub svay rieng
47                         Kim Veasna phone shop
48                       Lim Sorphorn phone shop
49                         Mao Sithan phone shop
50                         Yuk Samorn phone shop
51                              yes hub koh kong
52                                yes hub pailin
53                        Veng Hong 2 Phone Shop
54                             Veasna Phone Shop
55                           Van Seam Phone Shop
56                          Srey Neth Phone Shop
57                          yes hub Kampong Thom
58                       yes hub Kampong Chhnang
59                             yes hub prey veng

您不需要為此使用 selenium。 你可以通過 API 得到你想要的,然后在響應中使用 json 解析器。 像這樣: 在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM