def test_find_multiple(fake_html_1): soup = Soup(fake_html_1) result = soup.find("div", {"class": "baz"}) assert len(result) == 2 assert str(result[1]) == '<div class="baz">Oh No!</div>'
def test_find_text(fake_html_1): soup = Soup(fake_html_1) result = soup.find("p", {"id": "blarg"}) assert result.text == "Try for 2"
def test_find_first(fake_html_1): soup = Soup(fake_html_1) result = soup.find("p", mode="first") assert str(result) == "<p>'IDK!'</p>"
def test_find_with_attrs(fake_html_1): soup = Soup(fake_html_1) result = soup.find("p", {"id": "blarg"}) assert str(result) == '<p id="blarg">Try for 2</p>'
def test_find_no_match_auto(fake_html_1): soup = Soup(fake_html_1) result = soup.find("a", mode="auto") assert result == None
def test_find(fake_html_1): soup = Soup(fake_html_1) result = soup.find("span") assert str(result) == "<span>Hi</span>"
def test_find_no_match_first(fake_html_1): soup = Soup(fake_html_1) result = soup.find("a", mode="first") assert result == None
def test_find_no_match_all(fake_html_1): soup = Soup(fake_html_1) result = soup.find("a", mode="all") assert result == []
def test_find_mutliple_imgs(fake_html_3): soup = Soup(fake_html_3) result = soup.find("img") assert result[1].attrs["src"] == "bye.jpg"
def test_remove_tags(fake_html_4): soup = Soup(fake_html_4) result = soup.remove_tags() assert ( result == "I like soup and I really like cold soup I guess hot soup is okay too")
def test_find_nested_empty_tag(fake_html_3): soup = Soup(fake_html_3) result = soup.find("a", {"class": "foo"}) assert len(result) == 2
def test_find_strict(fake_html_2): soup = Soup(fake_html_2) result = soup.find("div", {"class": "foo"}, strict=True, mode="all") assert len(result) == 1
from gazpacho import get from gazpacho import Soup import pandas as pd import time position = 'F' base = f'https://www.cbssports.com/fantasy/hockey/stats' url = f'{base}/{position}/2019/restofseason/projections/' html = get(url) soup = Soup(html) # HTML: <tr class="TableBase-bodyTr "> rows = soup.find('tr', {'class': 'TableBase-bodyTr '}) row = rows[0] print(row)
def make_soup(url): html = get(url) soup = Soup(html) return soup
def make_soup(query, page=1): params = {'q': query, 'commit': 'Search', 'page': page} html = get(URL, params) soup = Soup(html) return soup