我一直在尝试使用python中的以下代码将数据插入到数据库中:
import sqlite3 as db
conn = db.connect('insertlinks.db')
cursor = conn.cursor()
db.autocommit(True)
a="asd"
b="adasd"
cursor.execute("Insert into links (link,id) values (?,?)",(a,b))
conn.close()
Run Code Online (Sandbox Code Playgroud)
代码运行没有任何错误.但是没有对数据库进行更新.我尝试添加conn.commit()但是它给出了一个错误,说找不到模块.请帮忙?
我正在尝试使用python扫描各种网站。以下代码对我来说很好用。
import urllib
import re
htmlfile =urllib.urlopen("http://google.com")
htmltext=htmlfile.read()
regex='<title>(.+?)</title>'
pattern=re.compile(regex)
title= re.findall(pattern,htmltext)
print title
Run Code Online (Sandbox Code Playgroud)
为了获取正文内容,我进行了如下更改:
import urllib
import re
htmlfile =urllib.urlopen("http://google.com")
htmltext=htmlfile.read()
regex='<body>(.+?)</body>'
pattern=re.compile(regex)
title= re.findall(pattern,htmltext)
print title
Run Code Online (Sandbox Code Playgroud)
上面的代码给了我一个空的方括号。我不知道我在做什么错。请帮忙