1. 程式人生 > >路飛學城—python爬蟲實戰密訓-—第1章

路飛學城—python爬蟲實戰密訓-—第1章

param 新聞 之前 code col 程序 find ... 定義

一.本節學習體會,心得:

  1. 因為之前只是看了Python基礎的內容,以為爬蟲的內容自己會看不懂,但是視頻裏的老師講得很好,生動易懂。
  2. 學習編程,就要親自練習,看視頻覺得懂了,自己親自做起來,就有了一點阻礙。

二.知識點總結:

  1. 爬蟲定義:通過程序去獲取網頁上自己想要的數據,也就是自動抓取數據。爬蟲通過分析html代碼,從中獲取文本,圖片,視頻.....
  2. 發送請求用http request,在這個歌之前要安裝requests 和bs4 模塊,在控制臺窗口裏用 pip install 模塊名 來進行安裝。
  3. request請求中包含,請求頭,請求體,method:url:params:data:
    json:headers:cookies。
  4. 爬取汽車之家新聞練習
    import requests
    from bs4 import BeautifulSoup
    ret = requests.get(url="https://www.autohome.com.cn/news/")
    ret.encoding = ret.apparent_encoding
    # print(ret.text)
    soup = BeautifulSoup(ret.text,html.parser)
    div = soup.find(name=div,id=auto-channel-lazyload-article)
    li_list 
    = div.find_all(name=li) for li in li_list: h3 = li.find(name=h3) if not h3: continue p = li.find(name=p) a = li.find(name=a) img = li.find(img) src = img.get(src) file_name = src.rsplit(__,1)[1] print(file_name) ret_img = requests.get( url
    = https:+src ) with open(file_name,wb) as f: f.write(ret_img.content)

路飛學城—python爬蟲實戰密訓-—第1章