1. 程式人生 > >爬蟲入門.

爬蟲入門.

url errno pos 入門 style _for perm open errno 13

requests爬蟲簡單框架:

import requests
try:
    r = requests.get(url)
    r.raise_for_status()  #如果狀態碼不是200會異常
    r.encoding = r.apparent_encoding
    return r.text
except:
    return 產生異常

path=rc:/abc.jpg
open(path, wb)

會報錯:PermissionError: [Errno 13] Permission denied: ‘c:/abc.jpg‘

path=rc:/1/abc.jpg
open(path, wb)

就不會。。。不明白

path = rc:/1/abc.jpg
with open(path, wb) as f:
    f.write(r.content)

關於content和text:https://www.jianshu.com/p/0e0336b370f3

爬蟲入門.