freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

分布式網(wǎng)絡(luò)爬蟲-總體設(shè)計(參考版)

2025-07-02 20:52本頁面
  

【正文】 }以上,我們就實現(xiàn)了數(shù)據(jù)庫的鏈接,運行CsdnBlogPageProcessor,并查看結(jié)果圖29 Console下的結(jié)果這是在eclipse下查看的結(jié)果,打開數(shù)據(jù)庫,發(fā)現(xiàn)數(shù)據(jù)也已經(jīng)保存了進去圖30 數(shù)據(jù)庫中的數(shù)據(jù)實驗結(jié)束后,將數(shù)據(jù)庫關(guān)閉服務(wù)圖31 關(guān)閉數(shù)據(jù)庫服務(wù)第40頁。 } catch (SQLException e) { ()。 (9, ())。 (7, ())。 (5, ())。 (3,())。 (1, ())。 } }鏈接完成后,要向數(shù)據(jù)庫中逐條插入數(shù)據(jù),因此再添加一個add函數(shù),代碼如下:public int add(CsdnBlog csdnBlog) { try { String sql = INSERT INTO `Shiyan`.`csdnblog` (`keyes`, `titles`, `content` , `dates`, `tags`, `category`, `views`, `ments`, `copyright`) VALUES (?, ?, ?, ?, ?, ?, ?, ?,?)。 } catch (ClassNotFoundException e) { ()。/*此處為添加要連接數(shù)據(jù)庫的信息,3306是接口,在使用WorkBench時有過設(shè)置,3306后邊是句庫名稱,下邊的’user=……’填寫數(shù)據(jù)庫的訪問密碼*/ conn = (url)。useUnicode=trueamp。 String url = jdbc:mysql://localhost:3306/Shiyan? + user=rootamp。 private Statement stmt = null。 } Override public String toString() { return CsdnBlog [key= + key + , title= + title + , content= + content + ,date= + date + , tags= + tags + , category= + category + , view= + view + , ments= + ments + , copyright= + copyright + ]。 } public int getCopyright() { return copyright。 } public int getComments() { return ments。 } public int getView() { return view。 } public String getCategory() { return category。 } public String getTags() { return tags。 } public String getDate() { return date。 } public String getTitle() { return title。 } public int getKey() { return key。 //文字內(nèi)容 public String getContent() { return content。// 評論人數(shù) private int copyright。// 分類 private int view。// 日期 private String tags。// 編號 private String title。 依然進入MySQL的官網(wǎng),翻到網(wǎng)頁最底部的DOWNLOAD,選擇MySQLWorkbench圖20 MySQLWorkbench下載1點擊DOWNLOAD下載并安裝圖21 MySQLWorkbench下載2安裝完成后雙擊打開圖22 MySQLWorkbench點擊‘+’圖標,進入數(shù)據(jù)庫配置,填寫配置信息圖23鏈接配置創(chuàng)建成功,雙擊數(shù)據(jù)庫輸入密碼進入圖24 MySQLWorkbench界面圖25 數(shù)據(jù)庫登錄圖形化管理工具只是為了方便結(jié)果的查看,現(xiàn)在我們使用cmd在MySQL中創(chuàng)建一個數(shù)據(jù)庫并建立一個名為csdnblog的表,用于存儲我們從網(wǎng)頁上爬到的數(shù)據(jù)信息,我已經(jīng)創(chuàng)建好了一個名為Shiyan的數(shù)據(jù)庫,在此只要創(chuàng)建表即可圖26 MySql建表1使用圖形化管理工具查看,發(fā)現(xiàn)Table下多出一張表,不過是空表圖27 MySql建表2 編寫鏈接數(shù)據(jù)庫文件圖28 總類圖 在連接數(shù)據(jù)庫之前,我們先要建立要插入數(shù)據(jù)的數(shù)據(jù)模型,即所要插入的數(shù)據(jù)由那幾項構(gòu)成以及他們的結(jié)構(gòu),新建一個CsdnBlog的JAVA文件,添加數(shù)據(jù)模型,并編寫獲取、修改相應(yīng)部分的代碼。 MySQL Workbench是下一代的可視化數(shù)據(jù)庫設(shè)計、管理的工具,它同時有開源和商業(yè)化的兩個版本。它是著名的數(shù)據(jù)庫設(shè)計工具DBDesigner4的繼任者。顯示“mysql”表示進入MySQL,可用TSQL語句對數(shù)據(jù)庫執(zhí)行各種操作。圖17 MySQL安裝2接下來配置環(huán)境變量編輯path系統(tǒng)變量,將G:\\bin添加到path變量。net start mysql將啟動MySQL服務(wù)。首先解壓到G:\\文件下,打開命令提示符以管理員身份運行,cd到G:\\bin下命令為:cd /d G:\\bin圖16 MySQL安裝1然后安裝MySQLmysqld install,運行命令后MySQL安裝成功。由于其社區(qū)版的性能卓越,搭配 PHP 和 Apache 可組成良好的開發(fā)環(huán)境。MySQL所使用的 SQL 語言是用于訪問數(shù)據(jù)庫的最常用標準化語言。MySQL 是最流行的關(guān)系型數(shù)據(jù)庫管理系統(tǒng)之一,在 WEB 應(yīng)用方面,MySQL是最好的 RDBMS (Relational Database Management System,關(guān)系數(shù)據(jù)庫管理系統(tǒng)) 應(yīng)用軟件。 } } public Site getSite() { return site。link_title39。 }else { (記錄數(shù):+temp++)。]).links().regex(://blog\\.csdn\\.net/chenyufeng1991/article/details/\\d+).all()。//用于獲取所有滿足(://blog\\.csdn\\.net/u012012240/article/month/2016/08/\\d+)這個正則表達式的鏈接 //區(qū)分是列表頁面還是信息頁面 if (().regex(article/list).match()) { ListString links = ().xpath([class=39。 if (()5) { (()1)。pagelist39。 } catch (JMException e) { ()。 //設(shè)置線程數(shù) //(5)。 public static void main( String[] args ) { //Spider是爬蟲的入口類,addurl為入口url Spider oschinaSpider = (new App()).addUrl() //Pipeline是結(jié)果輸出和持久化的接口,這里ConsolePipeline表示結(jié)果輸出到控制臺 .addPipeline(new ConsolePipeline())。 //執(zhí)行這個main方法,即可在控制臺看到抓取結(jié)果。public class App implements PageProcessor{ private Site site = ().setSleepTime(1)。import 。import 。import 。import 。 (【爬蟲結(jié)束】共抓取 + size + 篇文章,耗時約 + ((endTime startTime) / 1000) + 秒,已保存到數(shù)據(jù)庫,請查收!)。 // 從用戶博客首頁開始抓,開啟5個線程,啟動爬蟲 (new CsdnBlogPageProcessor()).addUrl( + username).thread(5).run()。 (【爬蟲開始】請耐心等待一大波數(shù)據(jù)到你碗里來...)。 } return ()。 } else { flag = true。 boolean flag = false。 } } // 把list轉(zhuǎn)換為string,用,分割 public static String listToString(ListString stringList) { if (stringList == null) { return null。 // 把對象存入數(shù)據(jù)庫 new CsdnBlogDao().add(csdnBlog)。]).regex(\\((\\d+)\\)).get()))。]/span[class=39。 // 設(shè)置評論人數(shù) ((() .xpath(//div[class=39。link_view39。article_r39。]/label/span/text()).all()))。 // 設(shè)置類別(可以有多個,用,來分割) ( listToString(().xpath(//div[class=39。link_categories39。article_l39。]/text()).get())。]/span[class=39。 // 設(shè)置日期 ( ().xpath(//div[class=39。article_content39。]/a/text()).get())。]//span[class=39。 // 設(shè)置標題 ( ().xpath(//div[class=39。// 文章數(shù)量加1 // 用CsdnBlog類來存抓取到的數(shù)據(jù),方便存入數(shù)據(jù)庫 CsdnBlog csdnBlog = new CsdnBlog()。]).links()// 限定其他列表頁獲取區(qū)域 .regex(/ + username + /article/list/\\d+) .replace(/ + username + /, + username + /)// 巧用替換給把相對url轉(zhuǎn)換成絕對url .all())。 // 添加其他列表頁 (().xpath(//div[id=39。article_list39。 public Site getSite() { return site。 // 設(shè)置csdn用戶名 private static int size = 0。/** * CSDN博客爬蟲 * * 可以爬取指定用戶的csdn博客所有文章,并保存到數(shù)據(jù)庫中。import 。import 。 具體代碼實現(xiàn) package 。(().links().regex((://github\\./\\w+/\\w+)).all())。JsonPath是于XPath很類似的一個語言,它用于從Json中快速定位一條內(nèi)容。(().links().regex((://github\\./\\w+/\\w+)).all())??陀^的說,它比XPath寫起來要簡單一些,但是如果寫復(fù)雜一點的抽取規(guī)則,就相對要麻煩一點。39。 對應(yīng)的Html是這樣子的:圖12 html導(dǎo)航 CSS選擇器CSS選擇器是與XPath類似的語言。entrytitle public39。entrytitle public39。 XPathXPath本來是用于XML中獲取元素的一種查詢語言,但是用于Html也是比較方便的。 } } 頁面元素的抽取第二部分是爬蟲的核心部分:對于下載到的Html頁面,你
點擊復(fù)制文檔內(nèi)容
試題試卷相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1