Привет, ребята, я очищал эти данные, и мой код работает нормально, но я не могу понять, как сохранить эти очищенные данные в файл Excel, и я еще больше запутался, посмотрев на другие решения и ответы
вот мой код
import time
import pandas as pd
from selenium import webdriver
from bs4 import BeautifulSoup
from selenium.webdriver.chrome.options import Options
from urllib.parse import urljoin
import openpyxl
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
##### Web scraper for infinite scrolling page #####
driver = webdriver.Chrome(executable_path='./chromedriver.exe')
driver.get("https://www.zomato.com/ncr/south-delhi-restaurants/fast-food?rating_range=4.0-5.0&category=2")
time.sleep(10) # Allow 2 seconds for the web page to open
scroll_pause_time = 1 # You can set your own pause time. My laptop is a bit slow so I use 1 sec
screen_height = driver.execute_script("return window.screen.height;") # get the screen height of the web
i = 1
count=0
while True:
# scroll one screen height each time
driver.execute_script("window.scrollTo(0, {screen_height}*{i});".format(screen_height=screen_height, i=i))
i += 1
time.sleep(scroll_pause_time)
# update scroll height each time after scrolled, as the scroll height can change after we scrolled the page
scroll_height = driver.execute_script("return document.body.scrollHeight;")
# Break the loop when the height we need to scroll to is larger than the total scroll height
if (screen_height) * i > scroll_height:
break
page_sources= BeautifulSoup(driver.page_source, "html.parser")
title=driver.find_elements_by_xpath("//a[@class='sc-jHZirH intUsQ']")
for i in title:
count += 1
name =i.find_element_by_xpath('./div/h4')
address = i.find_element_by_xpath('./p[1]')
#data = openpyxl.load_workbook('Bakery.xlsx')
df = pd.DataFrame({"Bakery Restaurants": name,"Address":address})
print(count)
driver.close()
это основной блок кода
page_sources= BeautifulSoup(driver.page_source, "html.parser")
title=driver.find_elements_by_xpath("//a[@class='sc-jHZirH intUsQ']")
for i in title:
count += 1
name =i.find_element_by_xpath('./div/h4')
address = i.find_element_by_xpath('./p[1]')
#data = openpyxl.load_workbook('Bakery.xlsx')
df = pd.DataFrame({"Bakery Restaurants": name,"Address":address})
print(count)
driver.close()
пожалуйста, помогите мне, я слишком запутался, любое предложение/решение будет оценено
Если ваши данные уже находятся в pandas df - pandas.pydata.org/pandas-docs/stable/reference/api/…
я не знаю, как использовать панд в этом, не могли бы вы помочь мне, пожалуйста, я никогда не делал этого