python爬取糗事百科数据并保存到sqlite中,命令行读出

import requests
import sqlite3
from bs4 import BeautifulSoup
class QSBK:
    def __init__(self):
        self.page=0
        self.items=[]
    def getItems(self):
            print('正在读取第'+str(self.page)+'页........')
            conn=sqlite3.connect('joke.db')
            cursor=conn.cursor()
            cursor.execute('create table if not exists jokes (id integer primary key autoincrement,item varchar,zan varchar)')
            url='http://www.qiushibaike.com/text/page/'+str(self.page)
            r=requests.get(url).content
            soup=BeautifulSoup(r,'html.parser').find_all('div',class_='content')
            soupz=BeautifulSoup(r,'html.parser').find_all('span',class_='stats-vote')
            i=0
            while i




你可能感兴趣的:(python爬虫)