mercredi 29 décembre 2021

Python Scraping Web page

I tried to Scrap all the 'a' tag placeholder values from this sample link:https://www.fundoodata.com/companies-in/list-of-apparel-stores-companies-in-india-i239

What I need is I want to copy only the names of 'a' tag and need to save it to a csv file

I'm beginner can anyone help me out below is my wrong code:

# importing the modules
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
import pandas as pd
import time
import os


link = "https://www.fundoodata.com/companies-in/list-of-apparel-stores-companies-in-india-i239"




# instantiating empty lists
nameList = []


for i in range(1) :
    driver = webdriver.Chrome(ChromeDriverManager().install())

 
    # fetching all the store details
    storeDetails = driver.find_elements_by_class_name('search-result')
 

 
    # iterating the storeDetails
    for j in range(len(storeDetails)):
         
        # fetching the name, address and contact for each entry
        name = storeDetails[j].find_element_by_class_name('heading').text
    
         
        myList = []
         
        nameList.append(name)


    driver.close()
 
     
# initialize data of lists.
data = {'Company Name': nameList,}
 
# Create DataFrame
df = pd.DataFrame(data)
print(df)
 
# Save Data as .csv
df.to_csv("D:\xxx\xxx\xx\xxx\demo.csv", mode='w+', header = False)



Aucun commentaire:

Enregistrer un commentaire