爬取起点中文网月票榜前500名网络小说

‘’’

参考自知乎https://zhuanlan.zhihu.com/p/26255754

Talk is cheap , show your code

所需模块: requests padndas BeautifulSoup

import requests
from bs4 import BeautifulSoup
import pandas
newsary=[]
for i in range(1,26):
    res=requests.get('http://r.qidian.com/yuepiao?chn=-1&page='+str(i))

    soup=BeautifulSoup(res.text,'html.parser')
    for news in soup.select('.rank-view-list li'):
        newsary.append({'title':news.select('a')[1].text,'name':news.select('a')[2].text,'style':news.select('a')[3].text,'describe':news.select('p')[1].text,'lastest':news.select('p')[2].text,'url':news.select('a')[0]['href']})
newsdf=pandas.DataFrame(newsary)
newsdf.to_excel('qidiantop500.xlsx')

成果截图: