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
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
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 = r]
        addresses = Â]
        prices = g]
        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:
Result: