无法使用selenium python获取所有foodpanda店铺名称

无法使用selenium python获取所有foodpanda店铺名称,python,selenium,beautifulsoup,python-requests,webdriver,Python,Selenium,Beautifulsoup,Python Requests,Webdriver,由于我只打印一个店名,所以我想从中提取所有店名 我想知道所有商店的名字请帮我 import time import requests from bs4 import BeautifulSoup import pandas as pd import numpy as np from selenium import webdriver url= "https://www.foodpanda.pk/restaurants/new?lat=24.9414896&lng=67.167

由于我只打印一个店名,所以我想从中提取所有店名 我想知道所有商店的名字请帮我

import time
import requests
from bs4 import BeautifulSoup
import pandas as pd
import numpy as np

from selenium import webdriver

url= "https://www.foodpanda.pk/restaurants/new?lat=24.9414896&lng=67.1676002&vertical=restaurants"
options = webdriver.ChromeOptions()
options.add_experimental_option("excludeSwitches", ['enable-automation'])
options.add_argument('--disable-blink-features=AutomationControlled')
options.add_argument(
    "user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36")
options.add_argument("--remote-debugging-port=9222")
driver = webdriver.Chrome('F:/chromedriver',options=options)
driver.get(url)
time.sleep(6)
pageSource = driver.page_source
SCROLL_PAUSE_TIME = 1



"""last_height = driver.execute_script("return document.body.scrollHeight")

this doesn't work due to floating web elements on youtube
"""

last_height = driver.execute_script("return document.documentElement.scrollHeight")
conte = None

while True:
    driver.execute_script("window.scrollTo(0,document.documentElement.scrollHeight);")
    time.sleep(SCROLL_PAUSE_TIME)
    new_height = driver.execute_script("return document.documentElement.scrollHeight")
    if new_height == last_height and conte:
       
       break
       
    last_height = new_height
    time.sleep(5)
    pageSource = driver.page_source
    soup = BeautifulSoup(pageSource, 'html.parser')
    conte = soup.find_all('ul',class_='vendor-list') 
    
for items in conte:
    ptitle= items.find('span',class_='name fn').text

print(ptitle)

您不需要漂亮的soap,只需调用headline元素并从中打印文本即可

您可以模拟页面发出的请求来获取所有数据,包括restarant名称。这样,您就不需要浏览器的开销

import requests, json

headers = {'x-disco-client-id': 'web'}

params = (
    ('latitude', '24.9414896'),
    ('longitude', '67.1676002'),
    ('language_id', '1'),
    ('include', 'characteristics'),
    ('new_sorting', 'true'),
    ('dynamic_pricing', '0'),
    ('configuration', 'Variant3'),
    ('country', 'pk'),
    ('customer_id', ''),
    ('customer_hash', ''),
    ('budgets', ''),
    ('cuisine', ''),
    ('sort', ''),
    ('food_characteristic', ''),
    ('use_free_delivery_label', 'false'),
    ('vertical', 'restaurants'),
    ('limit', '1000'),
    ('offset', '0'),
    ('customer_type', 'regular'),
)

r = requests.get('https://disco.deliveryhero.io/listing/api/v1/pandora/vendors', headers=headers, params=params)
data = json.loads(r.text)['data']
restuarants = {i['name'] for i in data['items']}
print(restuarants)

谢谢,如果我想削价,我应该用什么方法检查价格元素请帮助我在添加交货时产生问题给我错误请解决这个问题
import requests, json

headers = {'x-disco-client-id': 'web'}

params = (
    ('latitude', '24.9414896'),
    ('longitude', '67.1676002'),
    ('language_id', '1'),
    ('include', 'characteristics'),
    ('new_sorting', 'true'),
    ('dynamic_pricing', '0'),
    ('configuration', 'Variant3'),
    ('country', 'pk'),
    ('customer_id', ''),
    ('customer_hash', ''),
    ('budgets', ''),
    ('cuisine', ''),
    ('sort', ''),
    ('food_characteristic', ''),
    ('use_free_delivery_label', 'false'),
    ('vertical', 'restaurants'),
    ('limit', '1000'),
    ('offset', '0'),
    ('customer_type', 'regular'),
)

r = requests.get('https://disco.deliveryhero.io/listing/api/v1/pandora/vendors', headers=headers, params=params)
data = json.loads(r.text)['data']
restuarants = {i['name'] for i in data['items']}
print(restuarants)