Explore the world with an Airbnb $45 Gift Card! This gift card allows you to find vacation rentals, cabins, beach houses, and unique homes around the globe. Whether you're planning a getaway or looking for a unique experience, this gift card is perfect for travelers. Gift the joy of travel with Airbnb and create unforgettable memories!
To solve this problem, we need to reformat given system requirements into a structured HTML format. The goal is to generate clean and consistent HTML output for system requirements across different platforms, such as Windows, Mac, and Linux.
### Approach
1. **Input Structure Analysis**: The input can come in two forms:
- A flat list of dictionaries where each dictionary contains a single system component (e.g., OS, Processor, etc.).
- A list of dictionaries where each dictionary represents a complete system (e.g., Windows, Mac, Linux), each containing its own system requirements as an HTML string.
2. **HTML Generation**:
- For each system, we generate an HTML section starting with a heading, followed by a paragraph indicating "MINIMUM SPECS", and an unordered list of requirements.
- Each requirement is formatted with a span for the category and the corresponding requirement text.
3. **Parsing HTML Strings**: If the input contains HTML strings (as in the second example), we parse these strings to extract individual requirements and format them into the required structure.
### Solution Code
```python
from bs4 import BeautifulSoup
def generate_html(systems):
html_output = ""
for system in systems:
system_name = system.get("system", "PC")
requirements = system.get("requirement", [])
components = []
if isinstance(requirements, str):
soup = BeautifulSoup(requirements, 'html.parser')
lis = soup.find_all('li')
for li in lis:
category_tag = li.find(['span', 'strong'])
if category_tag:
category = category_tag.text.strip()
requirement_text = li.text.replace(category_tag.text, '').strip()
components.append({category: requirement_text})
else:
components = requirements
system_html = f"
\n"
system_html += f"
{system_name} System Requirements
\n"
system_html += "
\n"
system_html += "
MINIMUM SPECS
\n"
system_html += "
\n"
for component in components:
for category, requirement in component.items():
system_html += f" - \n"
system_html += f" {category} {requirement}\n"
system_html += "
\n"
system_html += "
\n"
system_html += "
\n
\n"
html_output += system_html
return html_output.strip()
```
### Explanation
- **Parsing Input**: The function `generate_html` processes each system in the input list. If the requirements are provided as an HTML string, it uses BeautifulSoup to parse the string and extract each requirement's category and text.
- **HTML Generation**: For each system, the function constructs an HTML section containing the system name, a heading, a "MINIMUM SPECS" paragraph, and an unordered list ofrequirements. Each requirement is formatted with a span for the category and the requirement text.
- **Concatenation**: The generated HTML for each system is concatenated to form the final output.
This approach ensures that the system requirements are consistently formatted and cleanly presented in HTML, adhering to the specified guidelines.
-
To redeem the card go to https://www.airbnb.pt/gift and log into your account.
-
Gift cards can be used for any stay, Experience or Online Experience on Airbnb.
-
Once you redeem your card and add the funds from the card to your account, you can go to Payment methods in your Account and check your balance.
-
Once a gift card has been added to your Airbnb account, the funds won’t expire.
分享