webscrapping when acces gets denied

C45HC0W

Regular Member
Joined
Jan 30, 2019
Messages
430
Reaction score
142
I want to read out this list of odds of different betting websites using python and request and beautifulsoup however my access gets denied
this is my code:

Code:
import requests
from bs4 import BeautifulSoup as bs

url = 'oddsportal.com/soccer/europe/europa-league/dynamo-kyiv-chelsea-lIjhcPn4/'

r = requests.get(url)
soup = bs(r.text,'html.parser')
txt ='bt1'
results = soup.find_all(id= "odds-data-table")
for result in results:
    info = result.text
    print(info)
 
what do you exactly mean by access gets denied ?

you have to check what's the output of this line :

r = requests.get(url)
 
You need to assign a correct URL first. It should start with http:// or https://

That may be your problem.

edit: just tried the snippet your provided. The request goes through if you add 'http://', but the URL returns a 404 anyway, so get a working URL first.
 
no thats not it. I removed it because everytime i write ht tp blackhat markes it as spam.
 
so when I run the code and print out the results between the html text shows up this:
The page you requested is not available.
Page not found
This page not exist on OddsPortal.com!

is this maybe cause because I didnt put in useragent or something?
 
Well you either have the url mispelled when you send it to requests or it's blocking the requests user agent. Lots of sites block python and wget.
 
Back
Top