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

📄 extractoruniversal.html

📁 用JAVA编写的,在做实验的时候留下来的,本来想删的,但是传上来,大家分享吧
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<a name="337" href="#337">337</a>         + <span class="string">"|(vn(/.*)?)"</span> <em class="comment">// vn  Vietnam</em><a name="338" href="#338">338</a>         + <span class="string">"|(vu(/.*)?)"</span> <em class="comment">// vu  Vanuatu</em><a name="339" href="#339">339</a>         + <span class="string">"|(wf(/.*)?)"</span> <em class="comment">// wf  Wallis and Futuna Islands</em><a name="340" href="#340">340</a>         + <span class="string">"|(ws(/.*)?)"</span> <em class="comment">// ws  Western Samoa</em><a name="341" href="#341">341</a>         + <span class="string">"|(ye(/.*)?)"</span> <em class="comment">// ye  Yemen</em><a name="342" href="#342">342</a>         + <span class="string">"|(yt(/.*)?)"</span> <em class="comment">// yt  Mayotte</em><a name="343" href="#343">343</a>         + <span class="string">"|(yu(/.*)?)"</span> <em class="comment">// yu  Yugoslavia</em><a name="344" href="#344">344</a>         + <span class="string">"|(za(/.*)?)"</span> <em class="comment">// za  South Africa</em><a name="345" href="#345">345</a>         + <span class="string">"|(zm(/.*)?)"</span> <em class="comment">// zm  Zambia</em><a name="346" href="#346">346</a>         + <span class="string">"|(zw(/.*)?)"</span> <em class="comment">// zw  Zimbabwe</em><a name="347" href="#347">347</a>         ;<a name="348" href="#348">348</a> <a name="349" href="#349">349</a>     <strong>protected</strong> <strong>long</strong> numberOfCURIsHandled = 0;<a name="350" href="#350">350</a>     <strong>protected</strong> <strong>long</strong> numberOfLinksExtracted= 0;<a name="351" href="#351">351</a> <a name="352" href="#352">352</a>     <em>/**<em>*</em></em><a name="353" href="#353">353</a> <em>     * Constructor</em><a name="354" href="#354">354</a> <em>     * @param name The name of the module.</em><a name="355" href="#355">355</a> <em>     */</em><a name="356" href="#356">356</a>     <strong>public</strong> <a href="../../../../org/archive/crawler/extractor/ExtractorUniversal.html">ExtractorUniversal</a>(String name) {<a name="357" href="#357">357</a>         <strong>super</strong>(name, <span class="string">"Link extraction on unknown file types. A best effort"</span> +<a name="358" href="#358">358</a>                 <span class="string">" extractor that looks at the raw byte code of any file "</span> +<a name="359" href="#359">359</a>                 <span class="string">"that has not been handled by another extractor and tries"</span> +<a name="360" href="#360">360</a>                 <span class="string">" to find URIs. Will only match absolute URIs."</span>);<a name="361" href="#361">361</a>         <a href="../../../../org/archive/crawler/settings/Type.html">Type</a> e;<a name="362" href="#362">362</a>         e = addElementToDefinition(<strong>new</strong> <a href="../../../../org/archive/crawler/settings/SimpleType.html">SimpleType</a>(ATTR_MAX_DEPTH_BYTES,<a name="363" href="#363">363</a>             <span class="string">"How deep to look into files for URI strings, in bytes"</span>,<a name="364" href="#364">364</a>             <strong>new</strong> Long(DEFAULT_MAX_DEPTH_BYTES)));<a name="365" href="#365">365</a>         e.setExpertSetting(<strong>true</strong>);<a name="366" href="#366">366</a>         e = addElementToDefinition(<strong>new</strong> <a href="../../../../org/archive/crawler/settings/SimpleType.html">SimpleType</a>(ATTR_MAX_URL_LENGTH,<a name="367" href="#367">367</a>             <span class="string">"Max length of URIs in bytes"</span>, <strong>new</strong> Long(DEFAULT_MAX_URL_LENGTH)));<a name="368" href="#368">368</a>         e.setExpertSetting(<strong>true</strong>);<a name="369" href="#369">369</a>     }<a name="370" href="#370">370</a> <a name="371" href="#371">371</a>     <strong>protected</strong> <strong>void</strong> extract(<a href="../../../../org/archive/crawler/datamodel/CrawlURI.html">CrawlURI</a> curi) {<a name="372" href="#372">372</a>         <strong>if</strong> (!isHttpTransactionContentToProcess(curi)) {<a name="373" href="#373">373</a>             <strong>return</strong>;<a name="374" href="#374">374</a>         }<a name="375" href="#375">375</a> <a name="376" href="#376">376</a>         numberOfCURIsHandled++;<a name="377" href="#377">377</a> <a name="378" href="#378">378</a>         <strong>try</strong> {<a name="379" href="#379">379</a>             InputStream instream = curi.getHttpRecorder().getRecordedInput().<a name="380" href="#380">380</a>                 getContentReplayInputStream();<a name="381" href="#381">381</a>             <strong>int</strong> ch = instream.read();<a name="382" href="#382">382</a>             StringBuffer lookat = <strong>new</strong> StringBuffer();<a name="383" href="#383">383</a>             <strong>long</strong> counter = 0;<a name="384" href="#384">384</a>             <strong>long</strong> maxdepth = ((Long)getAttribute(ATTR_MAX_DEPTH_BYTES,curi)).<a name="385" href="#385">385</a>                 longValue();<a name="386" href="#386">386</a>             <strong>if</strong>(maxdepth&lt;=0){<a name="387" href="#387">387</a>                 maxdepth = Long.MAX_VALUE;<a name="388" href="#388">388</a>             }<a name="389" href="#389">389</a>             <strong>long</strong> maxURLLength = ((Long)getAttribute(ATTR_MAX_URL_LENGTH,curi)).<a name="390" href="#390">390</a>                 longValue();<a name="391" href="#391">391</a>             <strong>boolean</strong> foundDot = false;<a name="392" href="#392">392</a>             <strong>while</strong>(ch != -1 &amp;&amp; ++counter &lt;= maxdepth) {<a name="393" href="#393">393</a>                 <strong>if</strong>(lookat.length()>maxURLLength){<a name="394" href="#394">394</a>                     <em class="comment">//Exceeded maximum length of a URL. Start fresh.</em><a name="395" href="#395">395</a>                     lookat = <strong>new</strong> StringBuffer();<a name="396" href="#396">396</a>                     foundDot = false;<a name="397" href="#397">397</a>                 }<a name="398" href="#398">398</a>                 <strong>else</strong> <strong>if</strong>(isURLableChar(ch)){<a name="399" href="#399">399</a>                     <em class="comment">//Add to buffer.</em><a name="400" href="#400">400</a>                     <strong>if</strong>(ch == 46){<a name="401" href="#401">401</a>                         <em class="comment">// Current character is a dot '.'</em><a name="402" href="#402">402</a>                         foundDot = <strong>true</strong>;<a name="403" href="#403">403</a>                     }<a name="404" href="#404">404</a>                     lookat.append((<strong>char</strong>)ch);<a name="405" href="#405">405</a>                 } <strong>else</strong> <strong>if</strong>(lookat.length() > 3 &amp;&amp; foundDot) {<a name="406" href="#406">406</a>                     <em class="comment">// It takes a bare mininum of 4 characters to form a URL</em><a name="407" href="#407">407</a>                     <em class="comment">// Since we have at least that many let's try link</em><a name="408" href="#408">408</a>                     <em class="comment">// extraction.</em><a name="409" href="#409">409</a>                     String newURL = lookat.toString();<a name="410" href="#410">410</a>                     <strong>if</strong>(looksLikeAnURL(newURL))<a name="411" href="#411">411</a>                     {<a name="412" href="#412">412</a>                         <em class="comment">// Looks like we found something.</em><a name="413" href="#413">413</a> <a name="414" href="#414">414</a>                         <em class="comment">// Let's start with a little cleanup as we may have</em><a name="415" href="#415">415</a>                         <em class="comment">// junk in front or at the end.</em><a name="416" href="#416">416</a>                         <strong>if</strong>(newURL.toLowerCase().indexOf(<span class="string">"http"</span>) > 0){<a name="417" href="#417">417</a>                             <em class="comment">// Got garbage in front of the protocol. Remove.</em><a name="418" href="#418">418</a>                             newURL = newURL.substring(newURL.toLowerCase().<a name="419" href="#419">419</a>                                 indexOf(<span class="string">"http"</span>));<a name="420" href="#420">420</a>                         }<a name="421" href="#421">421</a>                         <strong>while</strong>(newURL.substring(newURL.length()-1).equals(<span class="string">"."</span>))<a name="422" href="#422">422</a>                         {<a name="423" href="#423">423</a>                             <em class="comment">// URLs can't end with a dot. Strip it off.</em><a name="424" href="#424">424</a>                             newURL = newURL.substring(0,newURL.length()-1);<a name="425" href="#425">425</a>                         }<a name="426" href="#426">426</a> <a name="427" href="#427">427</a>                         <em class="comment">// And add the URL to speculative embeds.</em><a name="428" href="#428">428</a>                         numberOfLinksExtracted++;<a name="429" href="#429">429</a>                         curi.createAndAddLink(newURL,Link.SPECULATIVE_MISC,Link.SPECULATIVE_HOP);<a name="430" href="#430">430</a>                     }<a name="431" href="#431">431</a>                     <em class="comment">// Reset lookat for next string.</em><a name="432" href="#432">432</a>                     lookat = <strong>new</strong> StringBuffer();<a name="433" href="#433">433</a>                     foundDot = false;<a name="434" href="#434">434</a>                 } <strong>else</strong> <strong>if</strong>(lookat.length()>0) {<a name="435" href="#435">435</a>                     <em class="comment">// Didn't get enough chars. Reset lookat for next string.</em><a name="436" href="#436">436</a>                     lookat = <strong>new</strong> StringBuffer();<a name="437" href="#437">437</a>                     foundDot = false;<a name="438" href="#438">438</a>                 }<a name="439" href="#439">439</a>                 ch = instream.read();<a name="440" href="#440">440</a>             }<a name="441" href="#441">441</a>         } <strong>catch</strong>(IOException e){<a name="442" href="#442">442</a>             <em class="comment">//TODO: Handle this exception.</em><a name="443" href="#443">443</a>             e.printStackTrace();<a name="444" href="#444">444</a>         } <strong>catch</strong> (AttributeNotFoundException e) {<a name="445" href="#445">445</a>             <em class="comment">// TODO Auto-generated catch block</em><a name="446" href="#446">446</a>             e.printStackTrace();<a name="447" href="#447">447</a>         }<a name="448" href="#448">448</a>         <em class="comment">// Set flag to indicate that link extraction is completed.</em><a name="449" href="#449">449</a>         curi.linkExtractorFinished();<a name="450" href="#450">450</a>     }<a name="451" href="#451">451</a> 

⌨️ 快捷键说明

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