Skip to content Skip to sidebar Skip to footer

How To Scrape Text From A

Elements "id"

i'm learning how to scrape, then I'm not really advanced. I wuold scrape from bloomberg the company description. For instance from this page (https://www.bloomberg.com/research/sto

Solution 1:

In your solution Bloomberg blocks your request. Because it thinks you are a bot. You should use requests library and send user agent as header. You will get your expected output this way.

import requests
from bs4 import BeautifulSoup

header = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0'}
request = requests.get('https://www.bloomberg.com/research/stocks/private/snapshot.asp?privcapId=320105',headers=header)
soup = BeautifulSoup(request.text, 'html.parser')    
text = soup.find('p',id="bDescTeaser")
print(text.get_text())

Solution 2:

The get_text() must be given a open parenthesis. Change it from get_text) to get_text()

Post a Comment for "How To Scrape Text From A

Elements "id""