BeautifulSoup Quick Reference
=============================

INSTALLATION
  pip install beautifulsoup4

BASIC USAGE
  from bs4 import BeautifulSoup

  soup = BeautifulSoup(html, "html.parser")
  soup = BeautifulSoup(html, "lxml")

FINDING ELEMENTS
  soup.find("tag")                First matching tag
  soup.find_all("tag")           All matching tags
  soup.find("div", class_="x")   By class
  soup.find("div", id="main")    By id
  soup.find("a", href=True)      Has attribute
  soup.select("div.class")       CSS selector
  soup.select("#id")             By ID selector
  soup.select("div > p")         Direct children

ELEMENT PROPERTIES
  tag.text                 Text content
  tag.string               Direct string content
  tag.get_text(strip=True) Stripped text
  tag["href"]              Attribute value
  tag.get("href", "")      Attribute with default
  tag.attrs                All attributes (dict)
  tag.name                 Tag name

NAVIGATION
  tag.parent               Parent element
  tag.children             Direct children
  tag.descendants          All descendants
  tag.next_sibling         Next sibling
  tag.previous_sibling     Previous sibling

COMMON CTF PATTERNS
  # Extract all links
  for a in soup.find_all("a"):
      print(a.get("href"))

  # Extract form fields
  form = soup.find("form")
  for inp in form.find_all("input"):
      print(inp.get("name"), inp.get("value"))

  # Extract hidden fields
  hidden = soup.find_all("input", type="hidden")
  for h in hidden:
      print(h["name"], h["value"])

  # Extract table data
  for row in soup.find_all("tr"):
      cells = [td.text for td in row.find_all("td")]
      print(cells)

  # Find comments
  from bs4 import Comment
  comments = soup.find_all(string=lambda t: isinstance(t, Comment))
