Home > other >  Why do I always complains the last line, bosses, some directions
Why do I always complains the last line, bosses, some directions

Time:04-23

The import urllib. Request
The import re
The import sqlite3
Def searchWeb (HTML) :
Rows=[]




Def saveDB (rows) :
If len (rows)==0:
Return
Try:
Con=sqlite3. Connect (" students. Db ")
Cursor=con. Cursor ()
Try:
Cursor. The execute (drop table "students")
Except:
Pass
Try:
SQL="create table students (No varchar (128) primary key, Name a varchar (128), Gender varchar (128), the Age int)"
Cursor. The execute (SQL)
Except:
Pass
For the row in rows:
If (len (row)==4) :
SQL="insert into students (No, Name, Gender, Age) values (?,?,?,?,? ,? ,? ,?) "
Try:
No=row [0]
Name=row [1]
Gender=row [2]
Age=int (row [3])
Cursor. The execute (SQL, (No, Name, Gender, Age))
Except the Exception as err:
Print (err)
MIT ()
con.comCon. The close ()
Except the Exception as err:
Print (err);
Def showWeb (rows) :
Print (" Showing data from Web...
")For the row in rows:
Print (row)
Def showDB () :
Print (" Showing the data from the DB...
")Try:
Con=sqlite3. Connect (" students. Db ")
Cursor=con. Cursor ()
Cursor. The execute (" select * from students ")
Rows=cursor. Fetchall ()
For the row in rows:
Print (row)
Con. The close ()
Except the Exception as err:
Print (err)
Try:
Url="http://127.0.0.1:5000"
Resp=urllib. Request. Urlopen (url)
data=https://bbs.csdn.net/topics/resp.read ()
HTML=data. Decode (" utf-8 ")
Rows=searchWeb (HTML)
ShowWeb (rows)
SaveDB (rows)
ShowDB ()
Except the Exception as e:
print(e)