Reputation: 364
I am trying to send a request to the Louis Vuitton, but none of the the libraries that I have used are able to get a response. Even though i can access the site fine from the browser. Is there something im doing wrong?
I have used requests,urllib3 and BeautifulSoup and none of my trials with these libraries have been successful.
Code:
from urllib.request import Request, urlopen
from bs4 import BeautifulSoup as soup
url = 'https://us.louisvuitton.com/eng-us/products/pocket-organizer-monogram-other-nvprod2380073v'
req = Request(url , headers={'User-Agent': 'Chrome/84.0.4147.105'})
webpage = urlopen(req).read()
page_soup = soup(webpage, "html.parser")
title = page_soup.find("title")
print(title)
Output: Doesn't give me one, just stays blank until I KeyboardInterrupt.
Notes: The purpose of this project will be to monitor the website to detect if any changes occur. (Wallet goes back in stock)
Upvotes: 0
Views: 368
Reputation: 20098
You're headers
are incorrect.
from urllib.request import Request, urlopen
from bs4 import BeautifulSoup as soup
HEADERS = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)'
}
url = 'https://us.louisvuitton.com/eng-us/products/pocket-organizer-monogram-other-nvprod2380073v'
req = Request(url, headers=HEADERS)
webpage = urlopen(req).read()
page_soup = soup(webpage, "html.parser")
title = page_soup.find("title")
print(title.text)
Outputs:
Pocket Organizer Monogram Other in Blue - Small Leather Goods M69679 | LOUIS VUITTON ®
Upvotes: 1