<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>生信菜鸟团 &#187; bio-star</title>
	<atom:link href="http://www.bio-info-trainee.com/tag/bio-star/feed" rel="self" type="application/rss+xml" />
	<link>http://www.bio-info-trainee.com</link>
	<description>欢迎去论坛biotrainee.com留言参与讨论，或者关注同名微信公众号biotrainee</description>
	<lastBuildDate>Sat, 28 Jun 2025 14:30:13 +0000</lastBuildDate>
	<language>zh-CN</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=4.1.33</generator>
	<item>
		<title>生信常用论坛bio-star里面所有帖子爬取</title>
		<link>http://www.bio-info-trainee.com/323.html</link>
		<comments>http://www.bio-info-trainee.com/323.html#comments</comments>
		<pubDate>Wed, 18 Mar 2015 13:11:54 +0000</pubDate>
		<dc:creator><![CDATA[ulwvfje]]></dc:creator>
				<category><![CDATA[perl]]></category>
		<category><![CDATA[bio-star]]></category>
		<category><![CDATA[爬虫]]></category>
		<category><![CDATA[论坛]]></category>

		<guid isPermaLink="false">http://www.bio-info-trainee.com/?p=323</guid>
		<description><![CDATA[生信常用论坛bio-star里面所有帖子爬取 这个是爬虫专题第一集，主要讲如何分 &#8230; <a href="http://www.bio-info-trainee.com/323.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p style="text-align: center;"><b>生信常用论坛bio-star里面所有帖子爬取</b></p>
<p>这个是爬虫专题第一集，主要讲如何分析bio-star这个网站并爬去所有的帖子列表，及标签列表等等，前提是读者必须掌握perl，然后学习perl的LWP模块，可以考虑打印那本书读读，挺有用的！</p>
<p><a href="http://seqanswers.com/">http://seqanswers.com/</a> 这个是首页</p>
<p>http://seqanswers.com/forums/forumdisplay.php?f=18 这个共570个页面需要爬取</p>
<p>http://seqanswers.com/forums/forumdisplay.php?f=18&#038;order=desc&#038;page=1</p>
<p>http://seqanswers.com/forums/forumdisplay.php?f=18&#038;order=desc&#038;page=570</p>
<p>&lt;tbody id="threadbits_forum_18"&gt;这个里面包围这很多&lt;tr&gt;对，</p>
<p>前五个&lt;tr&gt;对可以跳过，里面的内容不需要</p>
<p><a href="http://www.bio-info-trainee.com/wp-content/uploads/2015/03/生信常用论坛bio_star462.png"><img class="alignnone size-full wp-image-324" src="http://www.bio-info-trainee.com/wp-content/uploads/2015/03/生信常用论坛bio_star462.png" alt="生信常用论坛bio_star462" width="554" height="154" /></a></p>
<p><span id="more-323"></span></p>
<p>这样就可以捕获到所有的目录啦！</p>
<p>首先我们看看如何爬去该论坛主页的板块构成，然后才进去各个板块里面继续爬去帖子。</p>
<p><a href="http://www.bio-info-trainee.com/wp-content/uploads/2015/03/生信常用论坛bio_star520.png"><img class="alignnone size-full wp-image-325" src="http://www.bio-info-trainee.com/wp-content/uploads/2015/03/生信常用论坛bio_star520.png" alt="生信常用论坛bio_star520" width="495" height="233" /></a></p>
<p>接下来看进入各个板块里面爬帖子的代码，可以直接复制张贴使用的！</p>
<p>[perl]</p>
<p>use LWP::Simple;</p>
<p>use HTML::TreeBuilder;</p>
<p>use Encode;</p>
<p>use LWP::UserAgent;</p>
<p>use HTTP::Cookies;</p>
<p>my $tmp_ua = LWP::UserAgent-&gt;new;    #UserAgent用来发送网页访问请求</p>
<p>$tmp_ua-&gt;timeout(15);                ##连接超时时间设为15秒</p>
<p>$tmp_ua-&gt;protocols_allowed( [ 'http', 'https' ] ); ##只允许http和https协议</p>
<p>$tmp_ua-&gt;agent(</p>
<p>&quot;Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727;.NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)&quot;</p>
<p>  ) ;</p>
<p>  $base='https://www.biostars.org';</p>
<p>  open FH_IN,&quot;index.txt&quot;;</p>
<p>  while (&lt;FH_IN&gt;) {</p>
<p>          chomp;</p>
<p>          @F=split;</p>
<p>          open FH_OUT,&quot;&gt;index-$F[1].txt&quot;;</p>
<p>         $total_pages=int($F[2]/40)+1;</p>
<p>          foreach (1..$total_pages){</p>
<p>         my $url = URI-&gt;new(&quot;$F[0]/?&quot;);</p>
<p>         my($sort,$page) = (&quot;update&quot;,$_);#</p>
<p>         $url-&gt;query_form(</p>
<p>           'page' =&gt; $page,</p>
<p>           'sort'  =&gt; $sort,</p>
<p>         );</p>
<p>                &amp;get_each_index($url,'FH_OUT');</p>
<p>                print $url.&quot;\n&quot;;</p>
<p>          }</p>
<p>  }</p>
<p>sub get_each_index{</p>
<p>        my ($url,$handle)=@_;</p>
<p>        $response = $tmp_ua-&gt;get($url);</p>
<p>        $html=$response-&gt;content;</p>
<p>        my $tree = HTML::TreeBuilder-&gt;new; # empty tree</p>
<p>        $tree-&gt;parse($html) or print &quot;error : parse html &quot;;</p>
<p>        my @list_title=$tree-&gt;find_by_attribute('class',&quot;post-title&quot;);</p>
<p>        foreach  (@list_title) {</p>
<p>                my $title =  $_-&gt;as_text();</p>
<p>                my $ref = $_-&gt;find_by_tag_name('a')-&gt;attr('href');</p>
<p>                print  $handle &quot;$base$href,$title\n&quot;;</p>
<p>        }</p>
<p> }</p>
<p>[/perl]</p>
<p>这样就可以爬去帖子列表了</p>
<p>https://www.biostars.org/t/rna-seq rna 1573</p>
<p>https://www.biostars.org/t/R R 1309</p>
<p>https://www.biostars.org/t/snp snp 1268</p>
<p>等等```````````````````````````````````````````````````````````</p>
<p>帖子文件如下，在我的群里面共享了所有的代码及帖子内容，欢迎加群201161227，生信菜鸟团！</p>
<p><a href="http://www.bio-info-trainee.com/wp-content/uploads/2015/03/生信常用论坛bio_star2283.png"><img class="alignnone size-full wp-image-326" src="http://www.bio-info-trainee.com/wp-content/uploads/2015/03/生信常用论坛bio_star2283.png" alt="生信常用论坛bio_star2283" width="218" height="482" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.bio-info-trainee.com/323.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
