Bs4 returning only version

Asked

Viewed 33 times

1

Opa, I’m creating a tool that searches the wordpress version and prints on screen (requests + bs4).

Excerpt from the code:

def versao():
    r = requests.get('https://'+f'{site}')
    html = r.text

    sopinha = BeautifulSoup(html, 'html.parser')

    versao = sopinha.find_all('meta', attrs={'name':'generator'})
    print(versao)

versao()

I wanted it to return only the wordpress version number, as for example: 4.9.2

But he returns all this: (I left in red what I want to return)

inserir a descrição da imagem aqui

  • You’ve searched all the elements <meta> page. It would not be the case to search only what you have name="generator" and treat its value?

  • I tried to take the goal but it gives the same result

1 answer

0


Try to use sopinha.find("meta", {"name":"generator"}), this should return you the full line in case you want to reduce the return further, try: sopinha.find("meta", {"name":"generator"})['content'].

Browser other questions tagged

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