PrB
PrB

Reputation: 33

Error while scraping the data.Please give me some solution stuck for days on it

import urllib2
from bs4 import BeautifulSoup

quote_page = 'https://www.bloomberg.com/quote/SPX:IND'
page = urllib2.urlopen(quote_page)
soup = BeautifulSoup(page,'html.parser')
print(soup.prettify())
name_box = soup.find("h1",attrs={"class" : "companyName__99a4824b"})
print(name_box.text)

I am trying to scrape data from Bloomberg Market website but not getting any success in it.I have mentioned the class name correctly but it does not display data. Please give me any solution. The following is the element:

<h1 class="companyName__99a4824b">S&amp;P 500 Index</h1>

I am new in web scraping & I am referring this site:

https://medium.freecodecamp.org/how-to-scrape-websites-with-python-and-beautifulsoup-5946935d93fe

Upvotes: 0

Views: 511

Answers (1)

DanielGibbs
DanielGibbs

Reputation: 10191

There's nothing inherently wrong with your code, but if you print out the response that you get from the website (print(soup.text)) you'll see that Bloomberg don't appear to like you scraping their website:

Terms of Service Violation Your usage has been flagged as a violation of our terms of service.

For inquiries related to this message please contact support. For sales inquiries, please visit http://www.bloomberg.com/professional/request-demo

If you believe this to be in error, please confirm below that you are not a robot by clicking "I'm not a robot" below.

Please make sure your browser supports JavaScript and cookies and that you are not blocking them from loading. For more information you can review the Terms of Service and Cookie Policy.

You could have a look at this question for possible ways to retrieve the information you want.

Upvotes: 1

Related Questions