非常好的視頻,我用Python3.7,requests庫,也實(shí)現(xiàn)了,雖然花了半天時(shí)間才調(diào)試出來,但也很值了??梢缘絟ttps://github.com/gongshishen/a_very_very_little_spider看到
2018-10-19
剛開始學(xué),python3做完了這個(gè)東西,碰到了幾個(gè)問題,不知道有沒有和我一樣的小伙伴_init_和__init__ 的區(qū)別,當(dāng)碰到異常 craw failed 可以debug看下流程,目前是可以跑的,不止只打印一個(gè)url,如果只打印了一個(gè)就是異常了,最后的解析,HTML打印漢字為16進(jìn)制,data['title'].encode('utf-8').decode('utf-8')可以改為漢字 代碼https://github.com/luckly1/baike.git
2018-10-03
python3錯(cuò)誤 之NameError: name 'cookielib' is not defined
問題:
Python 3 改成 http.cookiejar了
改進(jìn)辦法
print('第三種方法,cookie處理')
import http.cookiejar
cj = http.cookiejar.CookieJar()
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
urllib.request.install_opener(opener)
問題:
Python 3 改成 http.cookiejar了
改進(jìn)辦法
print('第三種方法,cookie處理')
import http.cookiejar
cj = http.cookiejar.CookieJar()
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
urllib.request.install_opener(opener)
2018-09-26
我用pycharm 編寫的:
import re
from bs4 import BeautifulSoup
html_doc = """
...
"""
soup = BeautifulSoup(html_doc,'html.parser',from_encoding='utf-8')
print '獲取所有的鏈接'
links = soup.find_all('a')
for link in links:
print link.name,link['href'],link.get_text()
.....
遇到的坑,新建的文件名不能包含bs4不然系統(tǒng)報(bào)錯(cuò)
import re
from bs4 import BeautifulSoup
html_doc = """
...
"""
soup = BeautifulSoup(html_doc,'html.parser',from_encoding='utf-8')
print '獲取所有的鏈接'
links = soup.find_all('a')
for link in links:
print link.name,link['href'],link.get_text()
.....
遇到的坑,新建的文件名不能包含bs4不然系統(tǒng)報(bào)錯(cuò)
2018-09-20