0

I need to extract data from div, but i have some problems here is my code:

import urllib.request as urllib2
from bs4 import BeautifulSoup
import requests
url = 'https://ru.investing.com/crypto/bitcoin/btc-usd-technical'
headers={'User-Agent': 'Mozilla/5.0'}
req = requests.get(url=url, headers=headers)
soup = BeautifulSoup(urllib2.urlopen("https://ru.investing.com/crypto/bitcoin/btc-usd-technical"), 'html', req)
result = soup.find_all("div", {"class":"summary"})

print(result)

This is the error i got:

raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden
HedgeHog
  • 22,146
  • 4
  • 14
  • 36
Andrey Kanava
  • 47
  • 1
  • 8
  • 1
    Does this answer your question? [Python requests. 403 Forbidden](https://stackoverflow.com/questions/38489386/python-requests-403-forbidden) – HedgeHog Jan 06 '22 at 16:16

1 Answers1

0

This error is not about BeautifulSoup, it is about urllib. HTTP 403 response code means that the servent doesn't allow you to access the page or the website. Maybe this is because you have sent too many requests, or maybe you are trying to access a special webpage (like admin panel or something). Also, i would suggest you to use requests library, rathen then urllib3. Perhaps at least you should go with urllib3, i guess.