完成作业2:爬虫
This commit is contained in:
31
2509165016 task-2-1-data-collection.py
Normal file
31
2509165016 task-2-1-data-collection.py
Normal 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)
|
||||
|
||||
Reference in New Issue
Block a user