Skip to main content
Question

Expose all rows

  • November 1, 2023
  • 1 reply
  • 0 views

mr_fme
Enthusiast
Forum|alt.badge.img+8

Hi,

 

In the workspace below, search the website and return many rows.

It´s possible to see in the Translation log, but in the result, only the last row is shown.

 

How can I receive all rows in the result?

 

Thank´s

1 reply

daveatsafe
Safer
Forum|alt.badge.img+19
  • Safer
  • November 2, 2023

Hi @mr_fme​,

Each iteration of the loop is writing to the same attributes on the same feature, so they are constantly being overwritten. The easiest solution is to write to list attributes instead, then using a ListExploder to break these up into individual rows.

import fme
import fmeobjects
import requests
from bs4 import BeautifulSoup
 
def processFeature(feature):
    url = 'https://www.vivareal.com.br/aluguel/sp/campinas/apartamento_residencial/3-quartos/#banheiros=2&com=academia&onde=,S%C3%A3o%20Paulo,Campinas,,,,,city,BR%3ESao%20Paulo%3ENULL%3ECampinas,,,&preco-ate=2500&preco-total=sim&quartos=3&vagas=1'
    # Defina a variável 'address' antes de usá-la
    address = None
    # Enviar uma solicitação GET para a URL
    response = requests.get(url)
    # Verificar se a solicitação foi bem-sucedida
    if response.status_code == 200:
        # Analisar o conteúdo da página com BeautifulSoup
        soup = BeautifulSoup(response.text, 'html.parser')
        
        # Encontre os elementos HTML que contêm informações sobre os imóveis
        property_listings = soup.find_all('div', class_='js-card-selector')
        
        # initialize output lists
        titles = []
        addresses = []
        prices = []
        for listing in property_listings:
            # Extrair informações relevantes dos elementos HTML
            title = listing.find('span', class_='property-card__title').text.strip()
            price = listing.find('div', class_='property-card__price').text.strip()
            address = listing.find('span', class_='property-card__address').text.strip()
            # Imprima as informações
            print(f'Título: {title}')
            print(f'Preço: {price}')
            print(f'Endereço: {address}')
            # append extracted info to output lists
            titles.append(title)
            addresses.append(address)
            prices.append(price)
 
        # add output lists to feature property list
        feature.setAttribute('property{}.title', titles)
        feature.setAttribute('property{}.address', addresses)
        feature.setAttribute('property{}.price', prices)
        print('\n')

ListExploder:

Screen Shot 2023-11-02 at 2.56.54 PMResult:

Screen Shot 2023-11-02 at 2.56.25 PM


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings