-1

I'm following this tutorial. But i got stuck here:

for container in containers:
    
    date = container.find('td', class_ = 'date-action').get_text()
    date = parser.parse(date.strip()[6:]).date()
    dateli.append(date) #make date relevant to current date

    description_container_1 = container.find('td', class_ = 'description TL_NPI_TransDesc')
    description_container_2 = description_container_1.find('a', class_ = 'transactionTitle')
    description = description_container_2.find('span', class_ = 'transTitleForEditDesc').get_text()
    descli.append(description)

    amount = container.find('td', class_ = ['amount positive TL_NPI_Amt', 'amount TL_NPI_Amt isDebit']).get_text()
    amtli.append(float(price_str(amount)))

My problem is how to replace the ('td', class_ = 'date-action') with 'div"[id*="wtDataMov"]', since its the only way to identify the lines i want to get is by a specific part of the a big id LT_BPINetEmpresas_wt37_block_wtMainContent_CW_Contas_Empresas_wtMovimentos_block_wtMovimentosList2_ctl04_wtDataMov.

Filipe
  • 21
  • 4

1 Answers1

0

To use a CSS selector use .select(). In your case to only find the first tag use .select_one()

...

date = container.select_one('div[id*=breakoutLeft]').get_text()
MendelG
  • 14,885
  • 4
  • 25
  • 52
  • Thanks for your time. Already tried that, i get the error: "AttributeError: ResultSet object has no attribute 'get_text'. You're probably treating a list of elements like a single element. Did you call find_all() when you meant to call find()?" – Filipe Aug 18 '20 at 08:38
  • Please refer to [this post](https://stackoverflow.com/questions/21997587/beautifulsoup-get-text-from-find-all). edit your full code if you still couldn't find a solution. – MendelG Aug 18 '20 at 12:05