一、Python爬取10页250条数据中的所有“书单”模块案例方法一:
#encoding=utf-8
import requests
from bs4 import BeautifulSoup
i=-25
while (i<225):
i=i+25
c=str(i)
resp = requests.get('https://book.douban.com/top250?start='+c+'')
soup = BeautifulSoup(resp.text, 'lxml')
alldiv = soup.find_all('div', class_='pl2')
for a in alldiv:
names = a.find('a')['title']
print(names)
二、Python爬取10页250条数据中的所有“书单”模块案例方法二:
# -*- coding:utf-8 -*-
import requests
from bs4 import BeautifulSoup
# 定义函数
def PT(c):
print("进入了该方法")
print("c:"+c)
resp = requests.get('https://book.douban.com/top250?start='+c+'')
soup = BeautifulSoup(resp.text, 'lxml')
alldiv = soup.find_all('div', class_='pl2')
for a in alldiv:
names = a.find('a')['title']
print(names)
i = -25
while (i < 225):
i = i + 25
A = str(i)
PT(A)