Files
task-2-1-data-collection/lxj01.py
2026-03-19 16:16:49 +08:00

13 lines
425 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from bs4 import BeautifulSoup
import requests
response = requests.get('https://example.com')
html_content = response.text
soup = BeautifulSoup(html_content,'lxml')
title = soup.find('title').string
print("页面标题:",title)
links = soup.find_all('a')
for link in links:
print("链接地址:",link.get('href'))
div_elements = soup.select('div.class_name')
for div in div_elements:
print("div内容",div.text)