非常感謝這位老師的講解,根據(jù)老師的講解,自己敲代碼實(shí)現(xiàn)了這個人生中第一個Python爬蟲,確實(shí)非常有意思,再次感謝老師,
根據(jù)自己的測試,有3個地方需要調(diào)整整之后才可以順利執(zhí)行
1、詞條頁面URL: /item/%E8%AE
原先是/view/41122.htm這種格式,但是百度百度百科已經(jīng)升級了,原先的無法使用,
對應(yīng)的代碼修改為:
links = soup.find_all('a',href=re.compile(r'/item/.*'))
根據(jù)自己的測試,有3個地方需要調(diào)整整之后才可以順利執(zhí)行
1、詞條頁面URL: /item/%E8%AE
原先是/view/41122.htm這種格式,但是百度百度百科已經(jīng)升級了,原先的無法使用,
對應(yīng)的代碼修改為:
links = soup.find_all('a',href=re.compile(r'/item/.*'))
2017-11-09
如果考慮版權(quán),專利,這樣做就是違法??紤]版權(quán),貌似只能做聚合,用于展示圖片,鏈接都是別人的。這讓我想到了淘寶客,阿里媽媽,京東快車,廣告聯(lián)盟,瞬間燃起激情。再想到羞羞網(wǎng)站,估計(jì)頂不住了!?
2017-11-05
現(xiàn)在網(wǎng)址已經(jīng)變成http://baike.baidu.com/item/Python,我們抓這個新網(wǎng)址需要修改成這句links = soup.find_all('a', href=re.compile(r"/item/(.*)"))
2017-11-04
新手還是把try except去掉吧 根據(jù)提示慢慢改代碼 就改出來了
python 3.X 版本
https://github.com/dagou1992/baike_spider
python 3.X 版本
https://github.com/dagou1992/baike_spider
2017-11-04
import urllib.request, http.cookiejar
urllib2 = urllib.request
cj = http.cookiejar.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
urllib2.install_opener(opener)
res = urllib2.urlopen('http://www.baidu.com')
cont = res.read()
if res.getcode() == 200:
print(cont)
urllib2 = urllib.request
cj = http.cookiejar.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
urllib2.install_opener(opener)
res = urllib2.urlopen('http://www.baidu.com')
cont = res.read()
if res.getcode() == 200:
print(cont)
2017-11-04