kopia lustrzana https://github.com/dgtlmoon/changedetection.io
27 wiersze
683 B
Python
27 wiersze
683 B
Python
from bs4 import BeautifulSoup
|
|
|
|
|
|
# Given a CSS Rule, and a blob of HTML, return the blob of HTML that matches
|
|
def css_filter(css_filter, html_content):
|
|
soup = BeautifulSoup(html_content, "html.parser")
|
|
html_block = ""
|
|
for item in soup.select(css_filter, separator=""):
|
|
html_block += str(item)
|
|
|
|
return html_block + "\n"
|
|
|
|
|
|
# Extract/find element
|
|
def extract_element(find='title', html_content=''):
|
|
|
|
#Re #106, be sure to handle when its not found
|
|
element_text = None
|
|
|
|
soup = BeautifulSoup(html_content, 'html.parser')
|
|
result = soup.find(find)
|
|
if result and result.string:
|
|
element_text = result.string.strip()
|
|
|
|
return element_text
|
|
|