⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 extractorhtmltest.html

📁 用JAVA编写的,在做实验的时候留下来的,本来想删的,但是传上来,大家分享吧
💻 HTML
📖 第 1 页 / 共 3 页
字号:
<a name="102" href="#102">102</a>             <strong>this</strong>.getClass().getName(), url.openStream(), <strong>null</strong>);<a name="103" href="#103">103</a>     }<a name="104" href="#104">104</a> <a name="105" href="#105">105</a>     <em class="comment">/*</em><a name="106" href="#106">106</a> <em class="comment">     * @see TestCase#tearDown()</em><a name="107" href="#107">107</a> <em class="comment">     */</em><a name="108" href="#108">108</a>     <strong>protected</strong> <strong>void</strong> tearDown() throws Exception {<a name="109" href="#109">109</a>         <strong>super</strong>.tearDown();<a name="110" href="#110">110</a>     }<a name="111" href="#111">111</a> <a name="112" href="#112">112</a>     <strong>public</strong> <strong>void</strong> testInnerProcess() throws IOException {<a name="113" href="#113">113</a>         <a href="../../../../org/archive/net/UURI.html">UURI</a> uuri = UURIFactory.getInstance(<span class="string">"http://"</span> + <strong>this</strong>.ARCHIVE_DOT_ORG);<a name="114" href="#114">114</a>         <a href="../../../../org/archive/crawler/datamodel/CrawlURI.html">CrawlURI</a> curi = setupCrawlURI(<strong>this</strong>.recorder, uuri.toString());<a name="115" href="#115">115</a>         <strong>this</strong>.extractor.innerProcess(curi);<a name="116" href="#116">116</a>         Collection links = curi.getOutLinks();<a name="117" href="#117">117</a>         <strong>boolean</strong> foundLinkToHewlettFoundation = false;<a name="118" href="#118">118</a>         <strong>for</strong> (Iterator i = links.iterator(); i.hasNext();) {<a name="119" href="#119">119</a>             <a href="../../../../org/archive/crawler/extractor/Link.html">Link</a> link = (Link)i.next();<a name="120" href="#120">120</a>             <strong>if</strong> (link.getDestination().toString().equals(<strong>this</strong>.LINK_TO_FIND)) {<a name="121" href="#121">121</a>                 foundLinkToHewlettFoundation = <strong>true</strong>;<a name="122" href="#122">122</a>                 <strong>break</strong>;<a name="123" href="#123">123</a>             }<a name="124" href="#124">124</a>         }<a name="125" href="#125">125</a>         assertTrue(<span class="string">"Did not find gif url"</span>, foundLinkToHewlettFoundation);<a name="126" href="#126">126</a>     }<a name="127" href="#127">127</a>     <a name="128" href="#128">128</a>     <strong>private</strong> <a href="../../../../org/archive/crawler/datamodel/CrawlURI.html">CrawlURI</a> setupCrawlURI(<a href="../../../../org/archive/util/HttpRecorder.html">HttpRecorder</a> rec, String url)<a name="129" href="#129">129</a>     		throws URIException {<a name="130" href="#130">130</a>         <a href="../../../../org/archive/crawler/datamodel/CrawlURI.html">CrawlURI</a> curi = <strong>new</strong> <a href="../../../../org/archive/crawler/datamodel/CrawlURI.html">CrawlURI</a>(UURIFactory.getInstance(url));<a name="131" href="#131">131</a>         curi.setContentSize(<strong>this</strong>.recorder.getRecordedInput().getSize());<a name="132" href="#132">132</a>         curi.setContentType(<span class="string">"text/html"</span>);<a name="133" href="#133">133</a>         curi.setFetchStatus(200);<a name="134" href="#134">134</a>         curi.setHttpRecorder(rec);<a name="135" href="#135">135</a>         <em class="comment">// Fake out the extractor that this is a HTTP transaction.</em><a name="136" href="#136">136</a>         curi.putObject(CoreAttributeConstants.A_HTTP_TRANSACTION,<a name="137" href="#137">137</a>             <strong>new</strong> Object());<a name="138" href="#138">138</a>         <strong>return</strong> curi;<a name="139" href="#139">139</a>     }<a name="140" href="#140">140</a>     <a name="141" href="#141">141</a>     <em>/**<em>*</em></em><a name="142" href="#142">142</a> <em>     * Test single net or local filesystem page parse.</em><a name="143" href="#143">143</a> <em>     * Set the uuri to be a net url or instead put in place a file</em><a name="144" href="#144">144</a> <em>     * named for this class under the unit test directory.</em><a name="145" href="#145">145</a> <em>     * @throws IOException</em><a name="146" href="#146">146</a> <em>     * @throws ReflectionException</em><a name="147" href="#147">147</a> <em>     * @throws MBeanException</em><a name="148" href="#148">148</a> <em>     * @throws AttributeNotFoundException</em><a name="149" href="#149">149</a> <em>     * @throws InvalidAttributeValueException</em><a name="150" href="#150">150</a> <em>     */</em><a name="151" href="#151">151</a>     <strong>public</strong> <strong>void</strong> testPageParse()<a name="152" href="#152">152</a>     throws InvalidAttributeValueException, AttributeNotFoundException,<a name="153" href="#153">153</a>     MBeanException, ReflectionException, IOException {<a name="154" href="#154">154</a>         <a href="../../../../org/archive/net/UURI.html">UURI</a> uuri = <strong>null</strong>;<a name="155" href="#155">155</a>         <a name="156" href="#156">156</a> <em class="comment">// DO</em><a name="157" href="#157">157</a> <em class="comment">//      uuri = UURIFactory.getInstance("http://www.xjmu.edu.cn/");</em><a name="158" href="#158">158</a> <em class="comment">// OR</em><a name="159" href="#159">159</a> <em class="comment">//        File f = new File(getTmpDir(), this.getClass().getName() +</em><a name="160" href="#160">160</a> <em class="comment">//        ".html");</em><a name="161" href="#161">161</a> <em class="comment">//        if (f.exists()) {</em><a name="162" href="#162">162</a> <em class="comment">//        	uuri = UURIFactory.getInstance("file://" +</em><a name="163" href="#163">163</a> <em class="comment">//        			f.getAbsolutePath());</em><a name="164" href="#164">164</a> <em class="comment">//        }</em><a name="165" href="#165">165</a> <em class="comment">// OR </em><a name="166" href="#166">166</a> <em class="comment">//      uuri = getUURI(URL or PATH)</em><a name="167" href="#167">167</a> <em class="comment">//</em><a name="168" href="#168">168</a> <em class="comment">// OR </em><a name="169" href="#169">169</a> <em class="comment">//      Use the main method below and pass this class an argument.</em><a name="170" href="#170">170</a> <em class="comment">//     </em><a name="171" href="#171">171</a>         <strong>if</strong> (uuri != <strong>null</strong>) {<a name="172" href="#172">172</a>         	runExtractor(uuri);<a name="173" href="#173">173</a>         }<a name="174" href="#174">174</a>     }<a name="175" href="#175">175</a>     <a name="176" href="#176">176</a>     <strong>protected</strong> <a href="../../../../org/archive/net/UURI.html">UURI</a> getUURI(String url) throws URIException {<a name="177" href="#177">177</a>         url = (url.indexOf(<span class="string">"://"</span>) > 0)? url: <span class="string">"file://"</span> + url;<a name="178" href="#178">178</a>         <strong>return</strong> UURIFactory.getInstance(url);<a name="179" href="#179">179</a>     }<a name="180" href="#180">180</a>     <a name="181" href="#181">181</a>     <strong>protected</strong> <strong>void</strong> runExtractor(<a href="../../../../org/archive/net/UURI.html">UURI</a> baseUURI)<a name="182" href="#182">182</a>     throws InvalidAttributeValueException, AttributeNotFoundException,<a name="183" href="#183">183</a>     MBeanException, ReflectionException, IOException {<a name="184" href="#184">184</a>         runExtractor(baseUURI, <strong>null</strong>);<a name="185" href="#185">185</a>     }<a name="186" href="#186">186</a>     <a name="187" href="#187">187</a>     <strong>protected</strong> <strong>void</strong> runExtractor(<a href="../../../../org/archive/net/UURI.html">UURI</a> baseUURI, String encoding)<a name="188" href="#188">188</a>     throws IOException, InvalidAttributeValueException,<a name="189" href="#189">189</a>     AttributeNotFoundException, MBeanException, ReflectionException {<a name="190" href="#190">190</a>         <strong>if</strong> (baseUURI == <strong>null</strong>) {<a name="191" href="#191">191</a>         	<strong>return</strong>;<a name="192" href="#192">192</a>         }<a name="193" href="#193">193</a>         <strong>this</strong>.extractor = createExtractor();<a name="194" href="#194">194</a>         URL url = <strong>new</strong> URL(baseUURI.toString());<a name="195" href="#195">195</a>         <strong>this</strong>.recorder = HttpRecorder.<a name="196" href="#196">196</a>             wrapInputStreamWithHttpRecord(getTmpDir(),<a name="197" href="#197">197</a>             <strong>this</strong>.getClass().getName(), url.openStream(), encoding);<a name="198" href="#198">198</a>         <a href="../../../../org/archive/crawler/datamodel/CrawlURI.html">CrawlURI</a> curi = setupCrawlURI(<strong>this</strong>.recorder, url.toString());<a name="199" href="#199">199</a>         <strong>this</strong>.extractor.innerProcess(curi);<a name="200" href="#200">200</a>         <a name="201" href="#201">201</a>         System.out.println(<span class="string">"+"</span> + <strong>this</strong>.extractor.report());<a name="202" href="#202">202</a>         <strong>int</strong> count = 0; <a name="203" href="#203">203</a>         Collection links = curi.getOutLinks();<a name="204" href="#204">204</a>         System.out.println(<span class="string">"+HTML Links (hopType="</span>+Link.NAVLINK_HOP+<span class="string">"):"</span>);<a name="205" href="#205">205</a>         <strong>if</strong> (links != <strong>null</strong>) {<a name="206" href="#206">206</a>             <strong>for</strong> (Iterator i = links.iterator(); i.hasNext();) {<a name="207" href="#207">207</a>                 <a href="../../../../org/archive/crawler/extractor/Link.html">Link</a> link = (Link)i.next();<a name="208" href="#208">208</a>                 <strong>if</strong> (link.getHopType()==Link.NAVLINK_HOP) {<a name="209" href="#209">209</a>                     count++;<a name="210" href="#210">210</a>                     System.out.println(link.getDestination());<a name="211" href="#211">211</a>                 }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -