完成作业2:爬虫

This commit is contained in:
2509165016
2026-03-26 15:35:50 +08:00
parent 89df5438eb
commit 256d2cb21d
3 changed files with 31 additions and 68 deletions

View File

@@ -0,0 +1,31 @@
import requests
from bs4 import BeatifulSoup
a = 0
url = f'https://ww.douban.com/doulist/3936288/?start={a}&sort=time&piayable=0&sub_type='
headers = {'User-Agent':'Mozilla/5.0 (windows NT 6.1; Win64; x64) AppleWebkit/537.36 (KHTHL, like Gecko) Chrome/96.0.4664.110 Safari/537.36'}
# print(soup)
# print('---------------------------')
# print('---------------------------')
# print('---------------------------')
response = requests.get(ur1, headers=headers,timeout=10)
response.encoding = 'utf-8'
soup = BeatifulSoup(response.text, 'html.parser')
print(soup)
for b in soup.find_all('a'):
# print(a)
href - b.get('herf','')
if '/subject/'in href:
title = b.get_text(strip=True)
print(title)
//'('@id="17923343"j/div/div(2)/div(4)/a
c - soup.select('a')
print(c)