app.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
import requests import pandas as pd # 🔍 Topic to search for topic = "python" # Change this to your desired topic # API endpoint for searching StackOverflow questions url = "https://api.stackexchange.com/2.3/search" params = { "order": "desc", "sort": "activity", "intitle": topic, # Search for questions with this topic in the title "site": "stackoverflow", "pagesize": 30, "page": 1 } response = requests.get(url, params=params) data = response.json() # Extract useful information questions = [] for item in data.get("items", []): questions.append({ "title": item["title"], "link": item["link"], "creation_date": item["creation_date"], "score": item["score"], "tags": ", ".join(item["tags"]), "owner": item["owner"].get("display_name", "Unknown"), "searched_topic": topic # Include the topic used in the search }) # Export to CSV df = pd.DataFrame(questions) df.to_csv("stackoverflow_questions.csv", index=False) print(f"Exported to stackoverflow_questions.csv for topic: {topic}") |