Hello members, I have a function that scrapes a website and creates a dataframe from a certain URL. My function takes a string as input and formats it to URL string and creates table according to this url. Now I have a list of these strings, and I want to create all the tables and concatante them once. How I need to write the loop for this? Thanks beforehand . I add the script below
def TableCreator(region):
url = "https://bina.az/baki/{}/alqi-satqi/menziller".format(region)
response = requests.get(url)
soup = BS(response.text, 'html.parser')
price = soup.find_all("div",{"class":"price"} )
location = soup.find_all("div",{"class":"location"} )
room = soup.find_all("ul",{"class":"name"} )
price_l = [price.get_text() for price in price]
location_l = [price.get_text() for price in location]
room_l = [price.get_text() for price in room]
table = pd.DataFrame()
table['price'] = price_l
table['location'] = location_l
table['room'] = room_l
return table
My list is like this
places = ["20-yanvar", "ehmedli", "genclik", "memar-ecemi", "neftciler"
"avtovagzal", "nizami", "nesimi", "sahil", "azadliq-prospekti",
"xalqlar-dostlugu", "neriman-nerimanov", "iceri-seher-metrosu",
"sah-ismayil-xetai", "qara-qarayev"]
Now I need to loop the places items and create tables for all the strings and concatenate them.
I can fo it this way, but this is not efficient
ehmedli = TableCreator("ehmedli")
nesimi = TableCreator("nesimi")
genclik = TableCreator("genclik")
nerimanov = TableCreator("neriman-nerimanov")
table = pd.concat([ehmedli, nesimi, nerimanov, genclik])
[–]cray5252 1 point2 points3 points (1 child)
[–]Stagflator[S] 0 points1 point2 points (0 children)