Skip to content

Commit ea536ff

Browse files
資料庫連結及其游標和資料操作方法
1 parent 610b77d commit ea536ff

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

MySQL.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# 2019.1/1.16:50, by Queenie Chen
2+
3+
from urllib.request import urlopen
4+
from bs4 import BeautifulSoup
5+
import re
6+
import pymysql
7+
from random import shuffle
8+
9+
conn = pymysql.connect(host='127.0.0.1', unix_socket='/tmp/mysql.sock', user='root', passwd=None, db='mysql', charset='utf8')
10+
cur = conn.cursor
11+
12+
cur.execute('') #內裝載mySQL指令
13+
14+
def insertPageIfNotExists(url):
15+
cur.execute('')
16+
if cur.rowcount == 0:
17+
cur.execute('')
18+
conn.commit()
19+
return cur.lastrowid
20+
else:
21+
return cur.fetchnon()[0]
22+
23+
def loadPage():
24+
cur.execute()
25+
pages = [row[1] for row in cur.fetchall()]
26+
return pages
27+
28+
def inserLink(fromPageId, toPageId):
29+
cur.execute()
30+
if cur.rowcount == 0:
31+
cur.execute()
32+
conn.commit()
33+
34+
cur.close()
35+
conn.close()
36+

0 commit comments

Comments
 (0)