實現爬蟲的思路

2021-10-09 11:43:41 字數 1060 閱讀 4109

網路爬蟲通過程式模擬瀏覽器請求站點的行為,把**返回的資料爬到本地,提取自己需要的資料,儲存起來使用。

爬蟲構成

1、確定目標**

2、解析目標**的資料資訊

3、程式模擬使用者發出http請求獲取資料

4、從獲取的資料中儲存到本地,刪選需要的相關資料

5、對獲取到的資料根據自己的需求使用

注意一般做爬蟲都會加上請求頭

user-agent:請求頭中如果沒有user-agent,目標**可能將你當做乙個非法使用者

cookies:cookie用來儲存登入資訊

爬蟲實踐

以下是關於網路爬蟲採集資料的實踐操作,通過爬蟲程式模擬使用者分析**採集資料解析資料儲存資料。**僅供參考:

import org.json.jsonobject;

import org.openqa.selenium.platform;

import org.openqa.selenium.proxy;

import org.openqa.selenium.firefox.firefoxdriver;

import org.openqa.selenium.firefox.firefoxprofile;

import org.openqa.selenium.htmlunit.htmlunitdriver;

import org.openqa.selenium.remote.capabilitytype;

import org.openqa.selenium.remote.desiredcapabilities;

import com.gargoylesoftware.htmlunit.defaultcredentialsprovider;

import com.gargoylesoftware.htmlunit.webclient;

public class firefoxdriverproxydemo

}

實現爬蟲的一般思路

實現爬蟲的套路 一 準備url 準備start url url位址規律不明顯,總數不確定 xpath 尋找url位址,部分引數在當前的響應中 比如,當前頁碼數和總的頁碼數在當前響應中 準備url list 頁碼總數明確 url位址規律明顯 二 傳送請求,獲取響應 新增隨機的user agent,反反...

python爬蟲思路

python2 爬蟲 從網頁上採取資料 爬蟲模組 urllib,urllib2,re,bs4,requests,scrapy,xlml 1.urllib 2.request 3.bs4 4.正則re 5種資料型別 1 數字number 2 字串string 3 列表list 中文在可迭代物件就是un...

通用小說爬蟲思路及JAVA實現

前面不是寫了個 爬蟲嗎,然後就覺得維護起來比較麻煩。想弄乙個通用的經過我的構想,覺得還是用正則匹配才行。首先用正則提取了正文,記過我在多個 的測試,已經差不多可以適配大多數了 貼下正則 正則抓取內容 test void test12 catch exception e pattern compile...