Чтобы найти курсы Python на Coursera, вы можете использовать API Coursera или методы очистки веб-страниц. Вот три метода, которые вы можете использовать для извлечения информации о курсе Python из Coursera с использованием примеров кода Python:
Метод 1. Использование API Coursera
import requests
# Define the Coursera API endpoint
url = "https://api.coursera.org/api/courses.v1?q=search&query=python"
# Send a GET request to the API endpoint
response = requests.get(url)
# Extract the course information from the response
courses = response.json()["elements"]
# Print the course names
for course in courses:
print(course["name"])
Метод 2: парсинг веб-страниц с помощью BeautifulSoup
import requests
from bs4 import BeautifulSoup
# Define the Coursera search URL
url = "https://www.coursera.org/courses?query=python"
# Send a GET request to the search URL
response = requests.get(url)
# Create a BeautifulSoup object
soup = BeautifulSoup(response.text, "html.parser")
# Find all course titles on the page
course_titles = soup.find_all("h2", class_="color-primary-text card-title headline-1-text")
# Print the course titles
for title in course_titles:
print(title.text)
Метод 3. Использование API поиска Coursera (неофициальный)
import requests
# Define the Coursera Search API endpoint
url = "https://www.coursera.org/api/catalogResults.v2?q=search&query=python"
# Send a GET request to the API endpoint
response = requests.get(url)
# Extract the course information from the response
courses = response.json()["elements"]
# Print the course names
for course in courses:
print(course["name"])