File size: 370 Bytes
dc4e6da
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from bs4 import Tag


def get_field_text(field: Tag) -> str:
    """

    Extract text from a BeautifulSoup Tag.



    Works for:

    - <input> elements (uses 'value' attribute)

    - Other tags (uses inner text)

    """
    if field.name == "input":
        return field.get("value", "").strip()  # type: ignore
    else:
        return field.text.strip()