Skip to content

Instantly share code, notes, and snippets.

@yshalsager
Last active December 6, 2023 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yshalsager/c388386d6d6493167269dd84da1bf7d6 to your computer and use it in GitHub Desktop.
Save yshalsager/c388386d6d6493167269dd84da1bf7d6 to your computer and use it in GitHub Desktop.
فتاوى نور على الدرب الصوتية
from pathlib import Path
import httpx
from parsel import Selector
root_url = "http://alandals.net"
response = httpx.get(f"{root_url}/Sections.php")
selector = Selector(response.text)
sections_links = selector.css("tr a::attr(href)").getall()
csv_file = Path("data.csv")
csv_file.write_text("section, question, url\n")
section_count = 1
for section in sections_links[1:]:
response = httpx.get(f"{root_url}/{section}", follow_redirects=True)
selector = Selector(response.text)
section_title = selector.css(
"tr:nth-child(1) > td > p > font > b::text").get()
questions_links = selector.css("tr a::attr(href)").getall()
question_count = 0
for question_link in questions_links[1:]:
response = httpx.get(f"{root_url}/{question_link}", follow_redirects=True)
selector = Selector(response.text)
question_text = selector.css("td[colspan='2'] center::text").get()
mp3_link = selector.css('a[href$=".mp3"]::attr(href)').get()
mp3_url = f"{root_url}/{mp3_link}"
question_count += 1
print(f"{section_count} - {question_count} - {mp3_url}")
with csv_file.open(mode="a", encoding="utf-8") as file:
file.write(f"{section_title},{question_text},{mp3_url}\n")
section_count += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment