Reputation: 55
So this is my second question regarding Beautiful Soup (sorry, im a beginner)
I was trying to fetch data from this website:
https://www.ccna8.com/ccna4-v6-0-final-exam-full-100-2017/
My Code:
from urllib.request import urlopen as uReq
from bs4 import BeautifulSoup as soup
url = 'https://www.ccna8.com/ccna4-v6-0-final-exam-full-100-2017/'
uClient = uReq(url)
page_html = uClient.read()
uClient.close()
page_soup = soup(page_html, "lxml")
print(page_soup)
But for some reason it returns an empty string.
I've been searching for similar threads and apparently it has something to do with the website using external api's , but this website doesn't.
Upvotes: 2
Views: 599
Reputation: 1433
It seems that the content-type of the response if gzip so you need to handle that before you can process the html response.
from urllib.request import urlopen as uReq
from bs4 import BeautifulSoup as soup
import gzip
url = 'https://www.ccna8.com/ccna4-v6-0-final-exam-full-100-2017/'
uClient = uReq(url)
page_html = gzip.decompress(uClient.read())
uClient.close()
page_soup = soup(page_html, "lxml")
print(page_soup)
Upvotes: 2
Reputation: 82775
try using requests
module
Ex:
import requests
from bs4 import BeautifulSoup as soup
url = 'https://www.ccna8.com/ccna4-v6-0-final-exam-full-100-2017/'
uClient = requests.get(url)
page_soup = soup(uClient.text, "lxml")
print(page_soup)
Upvotes: 2