要直接打印網(wǎng)頁顯示網(wǎng)址和時(shí)間,可以使用Python的requests
庫來獲取網(wǎng)頁內(nèi)容,然后使用BeautifulSoup
庫來解析HTML并提取網(wǎng)址和時(shí)間。以下是一個(gè)簡(jiǎn)單的示例:
import requests
from bs4 import BeautifulSoup
url = 'https://www.example.com' # 將此URL替換為你想要打印的網(wǎng)頁URL
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
# 提取網(wǎng)址
url_tag = soup.find('a', {'class': 'url'})
print('網(wǎng)址:', url_tag['href'])
# 提取時(shí)間
time_tag = soup.find('time')
if time_tag:
print('時(shí)間:', time_tag['datetime'])
else:
print('無法找到時(shí)間標(biāo)簽')
請(qǐng)確保已經(jīng)安裝了requests
和beautifulsoup4
庫。如果沒有安裝,可以使用以下命令安裝:
pip install requests beautifulsoup4
本文內(nèi)容根據(jù)網(wǎng)絡(luò)資料整理,出于傳遞更多信息之目的,不代表金鑰匙跨境贊同其觀點(diǎn)和立場(chǎng)。
轉(zhuǎn)載請(qǐng)注明,如有侵權(quán),聯(lián)系刪除。