File size: 787 Bytes
3d2aa58
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import requests
from bs4 import BeautifulSoup
from models.api import API

class Crawler:
    def __init__(self, url):
        self.url = url
        self.soup = self.get_soup()

    def get_soup(self):
        response = requests.get(self.url)
        return BeautifulSoup(response.text, 'html.parser')

    def crawl(self):
        api_list = []
        api_table = self.soup.find('table', {'class': 'markdown-table'})
        for row in api_table.find_all('tr')[1:]:
            cols = row.find_all('td')
            api = API(
                name=cols[0].text.strip(),
                description=cols[1].text.strip(),
                category=cols[2].text.strip(),
                link=cols[3].find('a')['href']
            )
            api_list.append(api)
        return api_list