简体   繁体   中英

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

检查网络屏幕截图

Website Link: https://www.yes.com.kh/support/find-shop

My code for now just manage to transfer the location name. It is very hard to get the longitude and latitude because of the code is in.network file. Any ideas guys? This is so hard.

 #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"]')))

This is my output. It just manage to capture all the data on the website but there are other data when you try to load more in all the provinces listed.

                                   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

You don't need to use selenium on this. You can get what you wanted thru API then use json parser on response. Something like this: 在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM