個人知識點總結

2021-10-04 12:27:17 字數 1999 閱讀 4886

'''

1. url headers 引數確定

url:

如果目標**是靜態的網頁,那就直接確定是他

遇到 ajax 非同步載入 需要通過 network 中 xhr 來通過抓包獲取資料

headers:

這個不多說了

2.關於請求方式

我用的最多的 還是 get 請求 ,還有乙個沒有怎麼學到post(就pass)

常用的第三方庫 requests

get請求攜帶的 常見引數:

url=目標位址,headers=請求頭,proxies=ip**,tomeout=超時設定

3.解析資料:

注意返回資料的編碼格式

萬能編碼符

r = requests.get(link,headers=headers).text

用到的庫:re bs4 xpath parsel(xpath的老大哥?) json

3.1庫名:re

也就是正則 了解的不多 常用規則 (.*?) 匹配所有括號裡的內容 (.*?) 匹配所有括號裡的數字

import re 為匯入方法 不需要進行資料轉換,re.findall(規則,目標(返回相應提的html**),re.s(一種模式,關於換行))

返回的資料結果為 列表 資料型別

關鍵字: ** 一類的案例

(3.2)

庫名 bs4 通過 pip install bs4

呼叫方法 from bs4 import beautifulsoup

需要進行資料轉換

html = resp.text

soup = beautifulsoup(html,'html.parser')

(3.2.1)

soup.find_all 用過確定目標資料 html標籤 class來確定資料

返回的資料結果為 列表 資料型別

關鍵字:**資訊—鄭州 **資訊—北京,貓眼等案例

(3.2.2)

soup.select(當中資料為 copy—copy selector)

返回的資料結果為 列表 資料型別

關鍵字:噹噹電子書 京東漢服

4.庫名:xpath 通過 pip install lxml

呼叫方法 from lxml import etree

資料轉換 html = etree.html(r.text)

用法(層層遞增的到達目標資料)

返回的資料結果為 列表 資料型別

5.庫名:parsel 通過 pip install parsel

呼叫方法 import parser

資料轉換

reapnse = requests.get(url,headers=headers)

html = parsel.selector(reapnse.text)

用法 html.xpath().extract()

(層層遞增的到達目標資料)

返回的資料結果為 列表 資料型別

關鍵字:美女手機桌布,貼吧美女

6.庫名:json 用來處理 json 資料型別的庫 而不是html **

呼叫 import json

資料轉換

resp_html = requests.get(link,headers=headers).text

html = json.loads(resp_html)

此時可以進行 re 等資料提取的方法來提取需要的資料

4.資料儲存

本地的 txt png json 不多解釋

呼叫全域性變數到某個函式裡

關於 xlsx 格式 import openpyxl

關鍵字 **資訊—鄭州,**資訊——北京

關於 .csv 格式 import csv

關鍵字 豆瓣電子書排行資訊獲取

'''

個人知識點總結

解除安裝 1.解除安裝 viewholder.iv antivirusitem clear.setonclicklistener new onclicklistener 2.監聽解除安裝廣播事件 1.建立監聽解除安裝的廣播接受者 private class uninstallreceiver ext...

知識點總結

1,迴圈中的中斷 continue 跳出此次迴圈,繼續for迴圈 break 跳出當前for迴圈 return 跳出當前方法 2,字串的操作 componentseparatedbystring stringbyreplacingoccurencesofstring withstring iskin...

知識點總結

oncreate onstrat onresume onpause onstop onrestart ondestroy standard 啟動activity都會產生乙個新的activity 預設模式 singletop 啟動activity允許多個,但不允許重疊 singletask 只允許有乙...