爬蟲學習(一)

2021-09-23 14:09:07 字數 1070 閱讀 7637

為了從網際網路上批量獲取資料,研究了下spider,在此記錄一筆學習經歷。

今天先了解下robots協議,也叫爬蟲協議,全稱是「網路爬蟲排除標準」(robots exclusion protocol),**通過robots協議告訴搜尋引擎哪些頁面可以抓取,哪些頁面不能抓取。

我們可以自定義爬蟲所使用的agent,比如我們可以按照以下方式定義agent,訪問時使用其中乙個。

ua_list = [

"mozilla/5.0 (windows nt 6.1; rv:40.0) gecko/20100101 firefox/40.0",#firwfox

"mozilla/5.0 (compatible, msie 11, windows nt 6.3; trident/7.0; rv:11.0) like gecko",#ie

"opera/9.99 (windows nt 5.1; u; zh-cn) presto/9.9.9",#opera

]ua = random.choice(ua_list) #pick one

遨遊瀏覽器提供了自定義user-agent的功能設定,大家可以自行選擇。

爬蟲學習(一)

def parse one page html pattern re.compile src re.s items re.findall pattern,html for item in items yield def write to file content with open result.t...

爬蟲學習(一)

url 統一資源定位符 聚焦爬蟲 根據特定的需求,從網上把資料去下來 爬蟲實現的思路 網頁的特點 每個網頁有自己的url 網頁是由html組成的 網頁傳輸的時候使用http和https協議 爬取的思路 使用乙個url 寫python 模擬瀏覽器傳送http請求 解析資料,提取出來指定的資料,通過一定...

python 爬蟲學習一

爬取目標 為aspx 使用到了 viewstate eventvalidation cookie來驗證。使用beautifulsoup來解析網頁內容。encoding utf 8 from bs4 import beautifulsoup import urllib import urllib2 d...