Python3爬取豆瓣新书速递书名+评分+作者+出版社+日期

 Python3爬取豆瓣新书速递

页面地址:https://book.douban.com/latest?icn=index-latestbook-all

Python3爬取豆瓣新书速递书名+评分+作者+出版社+日期_第1张图片

Python3爬取豆瓣新书速递书名+评分+作者+出版社+日期_第2张图片

import requests
import re

content = requests.get("https://book.douban.com/latest?icn=index-latestbook-all").text#获取网页源代码
pattern = re.compile('
  • .*?detail-frame.*?href="(.*?)">(.*?).*?color-lightgray">(.*?).*?color-gray">(.*?)

    ',re.S)#正则匹配 results = re.findall(pattern,content) #print(results) for result in results: url,name,pingjia,author = result print(url,name,pingjia.strip(),author.strip())#strip是用来去掉换行符
  •  

    你可能感兴趣的:(------python学习)