cloudscraper attempt for vps use
This commit is contained in:
13
pcslive.py
13
pcslive.py
@@ -1,5 +1,5 @@
|
|||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
import requests, time
|
import requests, time, cloudscraper
|
||||||
|
|
||||||
# class for storing the live races
|
# class for storing the live races
|
||||||
class LiveStats:
|
class LiveStats:
|
||||||
@@ -11,8 +11,11 @@ class LiveStats:
|
|||||||
# it also gets rid of all the horrible polygon stuff
|
# it also gets rid of all the horrible polygon stuff
|
||||||
def refresh_races(self):
|
def refresh_races(self):
|
||||||
# the entire front page of PCS loaded into soup
|
# the entire front page of PCS loaded into soup
|
||||||
self.req = requests.get("https://www.procyclingstats.com/")
|
#self.req = requests.get("https://www.procyclingstats.com/")
|
||||||
self.html = self.req.text
|
#self.html = self.req.text
|
||||||
|
|
||||||
|
self.scraper = cloudscraper.create_scraper()
|
||||||
|
self.req = self.scraper.get("https://www.procyclingstats.com/")
|
||||||
soup = BeautifulSoup(self.html, "html.parser")
|
soup = BeautifulSoup(self.html, "html.parser")
|
||||||
|
|
||||||
# narrow it down to the little green live stats boxes showing us what
|
# narrow it down to the little green live stats boxes showing us what
|
||||||
@@ -111,8 +114,8 @@ class Race:
|
|||||||
if self.url != "None":
|
if self.url != "None":
|
||||||
full_url = "https://www.procyclingstats.com/" + self.url
|
full_url = "https://www.procyclingstats.com/" + self.url
|
||||||
|
|
||||||
self.req = requests.get(full_url)
|
req = self.scraper.get(full_url)
|
||||||
html = self.req.text
|
html = req.text
|
||||||
soup = BeautifulSoup(html, "html.parser")
|
soup = BeautifulSoup(html, "html.parser")
|
||||||
return soup
|
return soup
|
||||||
return None
|
return None
|
||||||
|
|||||||
Reference in New Issue
Block a user