Python Forum

Full Version: Beautifulsoap can't get page title
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi
I can't get the tilte of the following page
http://cheirabem.com/mostraperfumes.aspx...Balenciaga
here is my code:
from bs4 import BeautifulSoup
import urllib.request
page3 = urllib.request.urlopen("http://cheirabem.com/mostraperfumes.aspx?marca=Balenciaga").read()
soup3 = BeautifulSoup(page3, "lxml")
titulo=soup3.findAll(attrs={"name":"title"})
print (titulo[0]['content'])

Any help with this issue?
Thank you
from bs4 import BeautifulSoup
import requests

url = 'http://cheirabem.com/mostraperfumes.aspx?marca=Balenciaga'
url_get = requests.get(url)
soup = BeautifulSoup(url_get.content, 'lxml')
print(soup.find('title').text.strip())
Output:
Balenciaga loja online perfumes, os seus perfumes mais baratos
So use Requests and not urllib,some more info in tutorial here.
Thank you. Problem solved