当当网图书畅销榜html
时间: 2023-11-29 21:46:21 浏览: 49
根据提供的引用内容,无法直接回答“当当网图书畅销榜html”的问题。但是,我们可以通过访问当当网的API来获取图书排行榜的数据,并将其呈现在HTML页面上。以下是一个简单的示例代码,可以获取当当网图书畅销榜前20名的书籍信息并在HTML页面上显示出来:
```python
import requests
from bs4 import BeautifulSoup
# 获取当当网图书畅销榜前20名的书籍信息
url = 'http://bang.dangdang.com/books/bestsellers/01.00.00.00.00.00-recent7-0-0-1-{}'
books = []
for i in range(1, 3):
res = requests.get(url.format(i))
soup = BeautifulSoup(res.text, 'html.parser')
items = soup.select('.bang_list li')
for item in items:
book = {}
book['title'] = item.select('.name a')[0].text.strip()
book['author'] = item.select('.publisher_info a')[0].text.strip()
book['price'] = item.select('.price_n')[0].text.strip()
books.append(book)
# 将书籍信息呈现在HTML页面上
html = '<html><head><title>当当网图书畅销榜</title></head><body><h1>当当网图书畅销榜</h1><ol>'
for book in books:
html += '<li>《{}》 作者:{} 价格:{}</li>'.format(book['title'], book['author'], book['price'])
html += '</ol></body></html>'
# 将HTML页面保存到文件中
with open('dangdang.html', 'w', encoding='utf-8') as f:
f.write(html)
```