Spaces:
Sleeping
Sleeping
File size: 1,862 Bytes
a6b51e7 | 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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | {
"cells": [
{
"cell_type": "code",
"execution_count": 42,
"id": "78e51fa0-70cf-4f3e-ae19-db8d76a5d7cb",
"metadata": {},
"outputs": [],
"source": [
"import requests as req\n",
"from bs4 import BeautifulSoup as b\n",
"import pandas as pd\n",
"d={}\n",
"for i in range(0,110):\n",
" res=req.get(f\"https://stackoverflow.com/questions?tab=newest&page={i}\")\n",
" soup1=b(res.text,\"html.parser\")\n",
" titles=soup1.select(\".s-post-summary\")\n",
" for k in range(len(titles)):\n",
" id_data=titles[k].get(\"data-post-id\")\n",
" href=titles[k].select_one(\".s-link\").get(\"href\")\n",
" url=r\"https://stackoverflow.com/\"+href\n",
" d[id_data]=url"
]
},
{
"cell_type": "code",
"execution_count": 43,
"id": "b5415465-7742-4cc1-aa0e-2d28411f06bc",
"metadata": {},
"outputs": [],
"source": [
"df=pd.DataFrame(data=list(d.items()), columns=[\"id\", \"questions_url\"])"
]
},
{
"cell_type": "code",
"execution_count": 44,
"id": "852b7aa1-1a0d-4e42-bebb-4969c9bbf712",
"metadata": {},
"outputs": [],
"source": [
"df.to_csv(r\"C:\\Users\\sss\\Documents\\datas_urls_questions.csv\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a82fe316-1da4-42cb-aae5-f214934eeda8",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|