Error 'Attributeerror' in python

Asked

Viewed 32 times

-1

I have that error in python with requests, web scraping!:

from bs4 import BeautifulSoup as bs
from requests import *

base_url = 'https://www.vagas.com.br/'
jobsurl = f'{base_url}/vagas-em-recife'
requestsjob = get(jobsurl)
requestsjob_bs = bs(requestsjob.text, 'html.parser')
vagas = requestsjob_bs.find('a', class_='link-detalhes-vaga').get_text()

for vaga in vagas:
    titulo_vaga = vagas.find('a').text
    print(titulo_vaga)

Error:

titulo_vaga = vagas.find('a').text
AttributeError: 'int' object has no attribute 'text'
  • Here is the stackoverflow in English. You can translate the question into English or redo the question in stackoverflow in English.

1 answer

1

You are using get_text() and .text functions. I Removed get_text() from your code and used get("title") in your loop, so it Works!

Please, Try this code:

from bs4 import BeautifulSoup as bs
from requests import *

base_url = 'https://www.vagas.com.br/'
jobsurl = f'{base_url}/vagas-em-recife'
requestsjob = get(jobsurl)
requestsjob_bs = bs(requestsjob.text, 'html.parser')
vagas = requestsjob_bs.findAll('a', class_='link-detalhes-vaga')

for vaga in vagas:
    titulo_vaga = vaga.get("title")
    print(titulo_vaga)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.