p29csdn博文爬蟲爬取

2021-09-27 02:21:25 字數 762 閱讀 3771

#csdn博文爬蟲爬取

#第一步關鍵是如何確定能夠唯一的找到那個文章

#先爬取整個所有博文的位址,然後在爬去、取改位址的內容

import urllib.request

import re

url=""

#需要瀏覽器偽裝

opener=urllib.request.build_opener()#建立opener物件先

opener.addheaders=[headers]

#安裝為全域性

urllib.request.install_opener(opener)

#url訪問時自帶報頭

data=urllib.request.urlopen(url).read().decode("utf-8","ignore")

pat=' \s*?\s*?rst=re.compile(pat).findall(data)#拿到首頁所有的博文鏈結

#print(rst)

for i in range(0,len(rst)):

#因為要與字串連線,所以先轉化為字串

localpath="d:\\pythonprojects\\result\\"+str(i)+".html"

thislink=rst[i]

urllib.request.urlretrieve(thislink,filename=localpath)

print("當前文章(第"+str(i)+"篇)爬取成功!")

node爬蟲爬取csdn資料

必須安裝node,我裝的是8.11.2版本,mac開發 發出http請求 superagent控制併發請求 async eventproxy分析網頁內容 cheerio 直接配置一下package.json dependencies 配置好後 nom install 安裝所需依賴 接下來開始寫爬蟲。...

爬蟲之爬取微博

3忘記了包含yeild的函式生成器目的是可以作為乙個迭代物件 貼源 importrequests fromurllib.parseimporturlencode frompyqueryimportpyqueryaspq base url header defget page page,value p...

Python爬蟲 爬取CSDN訪問量

import requests from bs4 import beautifulsoup 構造請求頭 headers 傳送get請求 r requests.get headers headers 處理 soup beautifulsoup r.text,html.parser 查詢class t ...