python BeautifulSoup抓取页面标题和url超链接
python BeautifulSoup抓取页面标题和url超链接
import requests
from bs4 import BeautifulSoup
res=requests.get('http://www.x14hack.com/')
res.encoding=('utf-8')
soup = BeautifulSoup(res.text,'html.parser')
for c in soup.select('div[class="post multi"] h2 a'):
url = c.get('href')
print(url)
title = soup.find_all('h2', class_="post-title")
for e in title:
print(e.text)
<< 上一篇