第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

腳本可以執(zhí)行成功,數(shù)據(jù)庫(kù)只有一條數(shù)據(jù),這是為什么?

http://img1.sycdn.imooc.com//58e8af51000181dc04800054.jpg

腳本可以執(zhí)行成功,數(shù)據(jù)庫(kù)只有一條數(shù)據(jù),這是為什么?

正在回答

9 回答

#我剛剛測(cè)試了自己的代碼,發(fā)現(xiàn)完全沒(méi)有問(wèn)題
#首先,這樣,你把下面這段代碼完全復(fù)制到你的運(yùn)行環(huán)境進(jìn)行測(cè)試
from?urllib.request?import?urlopen
from?bs4?import?BeautifulSoup
import?re
import?pymysql.cursors
resp?=?urlopen("https://en.wikipedia.org/wiki/Main_Page").read().decode("utf-8")
soup?=?BeautifulSoup(resp,"html.parser")
listUrls?=?soup.findAll("a",href=re.compile(r"^/wiki/"))
for?url?in?listUrls:
???if?not?re.search("\.(jpg|JPG)$",?url["href"]):
????print(url.get_text(),"<---->","https://en.wikipedia.org"+url["href"])
????#這里要縮進(jìn),不然后面面取得URL的值就是for遍歷的卒子后一個(gè)值,才會(huì)出現(xiàn)在打印過(guò)程中沒(méi)有問(wèn)題,
????#但是插入數(shù)據(jù)庫(kù)出現(xiàn)問(wèn)題,
????#不過(guò)我覺(jué)得在遍歷過(guò)程的外面連接數(shù)據(jù)庫(kù)可能好點(diǎn),我覺(jué)得每一次遍歷都會(huì)連接數(shù)據(jù)庫(kù)的代價(jià)太高了
????connection=pymysql.connect(
???????host='localhost',
???????user='root',
???????password='lqmysql',
???????db='wikiurl',
???????charset='utf8mb4'
????)
????try:
?????with?connection.cursor()?as?cursor:
?????????sql="insert?into?`urls`(`urlhref`,`urlname`)values(%s,%s)"
?????????cursor.execute(sql,(url.get_text(),"https://en.wikipedia.org"+url["href"]))
?????????connection.commit()
????finally:
???????connection.close()
#查看自己的運(yùn)行結(jié)果,應(yīng)該沒(méi)有什么問(wèn)題,我的就是這樣的
#
#
#然后,你復(fù)制下面這段代碼去測(cè)試一下
from?urllib.request?import?urlopen
from?bs4?import?BeautifulSoup
import?re
import?pymysql.cursors
resp?=?urlopen("https://en.wikipedia.org/wiki/Main_Page").read().decode("utf-8")
soup?=?BeautifulSoup(resp,"html.parser")
listUrls?=?soup.findAll("a",href=re.compile(r"^/wiki/"))
for?url?in?listUrls:
????if?not?re.search("\.(jpg|JPG)$",?url["href"]):
?????print(url.get_text(),"<---->","https://en.wikipedia.org"+url["href"])
connection=pymysql.connect(
????host='localhost',
????user='root',
????password='lqmysql',
????db='wikiurl',
????charset='utf8mb4'
)
try:
??with?connection.cursor()?as?cursor:
??????sql="insert?into?`urls`(`urlhref`,`urlname`)values(%s,%s)"
??????cursor.execute(sql,(url.get_text(),"https://en.wikipedia.org"+url["href"]))
??????connection.commit()
finally:
????connection.close()
#這一次,應(yīng)該只有一條語(yǔ)句插入了
#每次運(yùn)行完,可視化數(shù)據(jù)庫(kù)軟件要記得刷新一下


0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

慕粉3745191 提問(wèn)者

解決了
2017-04-09 回復(fù) 有任何疑惑可以回復(fù)我~

果然是格式問(wèn)題,前車(chē)之鑒.....

0 回復(fù) 有任何疑惑可以回復(fù)我~

我的天,我也遇到了這個(gè)問(wèn)題,,,,,好氣

0 回復(fù) 有任何疑惑可以回復(fù)我~

解決了……

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

追逐奔跑

如果是我猜對(duì)了問(wèn)題所在,希望你采納哦~~~
2017-04-09 回復(fù) 有任何疑惑可以回復(fù)我~

http://img1.sycdn.imooc.com//58e9dd7e0001a73e04680138.jpg

看上圖

0 回復(fù) 有任何疑惑可以回復(fù)我~
from?urllib.request?import?urlopen
from?bs4?import?BeautifulSoup
import?re
import?pymysql.cursors
resp?=?urlopen("https://en.wikipedia.org/wiki/Main_Page").read().decode("utf-8")
soup?=?BeautifulSoup(resp,"html.parser")
listUrls?=?soup.findAll("a",href=re.compile("^/wiki/"))
for?url?in?listUrls:
???if?not?re.search("\.(jgp||JPG)$",?url["href"]):
????print(url.get_text(),"<---->","https://en.wikipedia.org"+url["href"])
????#這里要縮進(jìn),不然后面面取得URL的值就是for遍歷的卒子后一個(gè)值,才會(huì)出現(xiàn)在打印過(guò)程中沒(méi)有問(wèn)題,
????#但是插入數(shù)據(jù)庫(kù)出現(xiàn)問(wèn)題,
????#不過(guò)我覺(jué)得在遍歷過(guò)程的外面連接數(shù)據(jù)庫(kù)可能好點(diǎn),我覺(jué)得每一次遍歷都會(huì)連接數(shù)據(jù)庫(kù)的代價(jià)太高了
????connection=pymysql.connect(
???????host='localhost',
???????user='root',
???????password='lqmysql',
???????db='wikiurl',
???????charset='utf8mb4'
????)
????try:
?????with?connection.cursor()?as?cursor:
?????????sql="insert?into?`urls`(`urlhref`,`urlname`)values(%s,%s)"
?????????cursor.execute(sql,(url.get_text(),"https://en.wikipedia.org"+url["href"]))
?????????connection.commit()
????finally:
???????connection.close()


0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

慕粉3745191 提問(wèn)者

還是一樣,,,我排查了,運(yùn)行一次腳本,數(shù)據(jù)庫(kù)增加一條。插入的是最后的一條數(shù)據(jù)。
2017-04-09 回復(fù) 有任何疑惑可以回復(fù)我~

from urllib.request import urlopen
from bs4 import BeautifulSoup
import re
import pymysql.cursors
resp = urlopen("https://en.wikipedia.org/wiki/Main_Page").read().decode("utf-8")
soup = BeautifulSoup(resp,"html.parser")
listUrls = soup.findAll("a",href=re.compile("^/wiki/"))
for url in listUrls:
? ?if not re.search("\.(jgp||JPG)$", url["href"]):
? ? print(url.get_text(),"<---->","https://en.wikipedia.org"+url["href"])
connection=pymysql.connect(
? ?host='localhost',
? ?user='root',
? ?password='lqmysql',
? ?db='wikiurl',
? ?charset='utf8mb4'
)
try:
?with connection.cursor() as cursor:
? ? ?sql="insert into `urls`(`urlhref`,`urlname`)values(%s,%s)"
? ? ?cursor.execute(sql,(url.get_text(),"https://en.wikipedia.org"+url["href"]))
? ? ?connection.commit()
finally:
? ?connection.close()

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

追逐奔跑

如果不是慕課網(wǎng)回復(fù)過(guò)程中把你的代碼進(jìn)行的縮進(jìn),那么就是格式出了問(wèn)題,Python是一個(gè)嚴(yán)格縮進(jìn)的語(yǔ)言,理應(yīng)從connection一直到最后一行,向后縮進(jìn)一次,或者說(shuō)是向后四個(gè)空格
2017-04-09 回復(fù) 有任何疑惑可以回復(fù)我~
#2

慕粉3745191 提問(wèn)者 回復(fù) 追逐奔跑

這個(gè)要怎么排查?
2017-04-09 回復(fù) 有任何疑惑可以回復(fù)我~

額,帥哥,總共不到100行代碼,你完全可以全部粘出來(lái)的,單獨(dú)這一部分應(yīng)該是沒(méi)有問(wèn)題的。


0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

慕粉3745191 提問(wèn)者

我運(yùn)行一次腳本,數(shù)據(jù)庫(kù)里插入一條數(shù)據(jù)
2017-04-09 回復(fù) 有任何疑惑可以回復(fù)我~

是不是數(shù)據(jù)庫(kù)操作成了update?明顯是沒(méi)有Insert吧

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

慕粉3745191 提問(wèn)者

執(zhí)行sql是insert
2017-04-09 回復(fù) 有任何疑惑可以回復(fù)我~
#2

追逐奔跑 回復(fù) 慕粉3745191 提問(wèn)者

不介意把你寫(xiě)的代碼粘出來(lái)吧?
2017-04-09 回復(fù) 有任何疑惑可以回復(fù)我~
#3

慕粉3745191 提問(wèn)者 回復(fù) 追逐奔跑

try: with connection.cursor() as cursor: sql="insert into `urls`(`urlhref`,`urlname`)values(%s,%s)" cursor.execute(sql,(url.get_text(),"https://en.wikipedia.org"+url["href"])) connection.commit() finally: connection.close()
2017-04-09 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

腳本可以執(zhí)行成功,數(shù)據(jù)庫(kù)只有一條數(shù)據(jù),這是為什么?

我要回答 關(guān)注問(wèn)題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)