| 726 | text = body[:1_500_000].decode("utf-8", errors="replace") |
| 727 | soup = None |
| 728 | with contextlib.suppress(Exception): |
| 729 | from bs4 import BeautifulSoup # type: ignore |
| 730 | soup = BeautifulSoup(text, "html.parser") |
| 731 | |
| 732 | def meta_value(*names: str) -> Optional[str]: |
| 733 | if soup is not None: |
| 734 | for name in names: |
| 735 | tag = soup.find("meta", attrs={"name": name}) or soup.find("meta", attrs={"property": name}) |
| 736 | if tag and tag.get("content"): |
| 737 | return str(tag.get("content")).strip() |
| 738 | for name in names: |
| 739 | patterns = [ |
| 740 | rf"<meta[^>]+(?:name|property)=[\"']{re.escape(name)}[\"'][^>]+content=[\"']([^\"']*)", |