summaryrefslogtreecommitdiff
path: root/jfr_playoff/remote.py
blob: b687740dc9df9badb4de4703bc6f9d9017d9cb9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import re

import requests

from bs4 import BeautifulSoup as bs

class RemoteUrl:

    url_cache = {}

    @classmethod
    def fetch(cls, url):
        if url not in cls.url_cache:
            request = requests.get(url)
            encoding_match = re.search(
                'content=".*;( )?charset=(.*)"',
                request.content, re.IGNORECASE)
            if encoding_match:
                request.encoding = encoding_match.group(2)
            cls.url_cache[url] = request.text
        return bs(cls.url_cache[url], 'lxml')