| | import requests |
| | from bs4 import BeautifulSoup |
| |
|
| | def search_team_info(team_name): |
| | search_query = f"足球 {team_name} 隊 資料" |
| | search_results = [] |
| |
|
| | |
| | google_url = f"https://www.google.com/search?q={search_query}" |
| | google_response = requests.get(google_url) |
| | google_soup = BeautifulSoup(google_response.text, 'html.parser') |
| | google_results = google_soup.find_all('h3', class_='t') |
| | for result in google_results: |
| | search_results.append(result.text) |
| |
|
| | |
| |
|
| | return search_results |
| |
|
| | def main(): |
| | team_name = input("請輸入球隊名稱:") |
| | team_info = search_team_info(team_name) |
| | for info in team_info: |
| | print(info) |
| |
|
| | if __name__ == "__main__": |
| | !pip install beautifulsoup4 |
| | main() |