Google Map错误列表索引必须是整数或切片,而不是webelement
我正在尝试刮擦电话号码
,但它们向我展示了您的列表必须是整数而不是Web元素
我尝试了不同的批准,但他们会向我展示这些错误这是链接
import time
from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from webdriver_manager.chrome import ChromeDriverManager
import pandas as pd
options = webdriver.ChromeOptions()
# options.add_argument("--headless")
options.add_argument("--no-sandbox")
options.add_argument("--disable-gpu")
options.add_argument("--window-size=1920x1080")
options.add_argument("--disable-extensions")
chrome_driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()),options=options)
data=[]
def supplyvan_scraper():
with chrome_driver as driver:
driver.implicitly_wait(15)
URL = 'https://www.google.com/maps/search/dentist+uk/@31.5688259,74.2388013,12z/data=!3m1!4b1'
driver.get(URL)
time.sleep(3)
page_links = [element.get_attribute('href') for element in driver.find_elements(By.XPATH, '//*[@class="hfpxzc"]')]
# visit all the links
for link in page_links:
wev={}
driver.get(link)
time.sleep(2)
link=driver.find_elements(By.XPATH, "//div[@class='RcCsl fVHpi w4vB1d NOE9ve M0S7ae AG25L']")
for i in link:
if '+' in link[i].get():
phone=driver.find_element(By.XPATH, "//div[@class='Io6YTe fontBodyMedium']").text
print(phone)
time.sleep(2)
supplyvan_scraper()
这些行中显示错误:
if '+' in link[i]:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用Regex检查电话号码并轻松打印出
电话号码仅包含
DIGITS
,并以+
标志开始因此,您可以使用此模式 -
^\+。*\ d $
您可以搜索所有文本元素,并使用此模式
工作代码 -
输出 -输出 -
You can use regex to check the phone number and print it out easily
Phone number contains only
digits
and starting with a+
signSo you may use this pattern -
^\+.*\d$
You can search all the text elements and find the number using this pattern
working code -
Output -