<?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; seq-answer</title>
	<atom:link href="http://www.bio-info-trainee.com/tag/seq-answer/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>生信常用论坛seq-answer里面所有帖子爬取</title>
		<link>http://www.bio-info-trainee.com/328.html</link>
		<comments>http://www.bio-info-trainee.com/328.html#comments</comments>
		<pubDate>Wed, 18 Mar 2015 13:34:24 +0000</pubDate>
		<dc:creator><![CDATA[ulwvfje]]></dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[计算机基础]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[seq-answer]]></category>
		<category><![CDATA[爬虫]]></category>

		<guid isPermaLink="false">http://www.bio-info-trainee.com/?p=328</guid>
		<description><![CDATA[生信常用论坛seq-answer里面所有帖子爬取 这个是爬虫专题第二集，主要讲如 &#8230; <a href="http://www.bio-info-trainee.com/328.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p style="text-align: center;"><b>生信常用论坛seq-answer里面所有帖子爬取</b></p>
<p>这个是爬虫专题第二集，主要讲如何分析seq-answer这个网站并爬去所有的帖子列表，及标签列表等等，前提是读者必须掌握perl，然后学习perl的LWP模块，可以考虑打印那本书读读，挺有用的！</p>
<p>其实爬虫是个人兴趣啦，跟这个网站没多少关系，本来一个个下载，傻瓜式的重复也能达到目的。我只是觉得这样很有技术范，哈哈，如何大家不想做傻瓜式的操作可以自己学习学习，如果不懂也可以问问我！</p>
<p>http://seqanswers.com/这个是主页</p>
<p>http://seqanswers.com/forums/forumdisplay.php?f=18 这个共570个页面需要爬取</p>
<p>其中f=18 代表我们要爬去的bioinformatics板块里面的内容</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><span id="more-328"></span></p>
<p><a href="http://www.bio-info-trainee.com/wp-content/uploads/2015/03/生信常用论坛seq556.png"><img class="alignnone size-full wp-image-329" src="http://www.bio-info-trainee.com/wp-content/uploads/2015/03/生信常用论坛seq556.png" alt="生信常用论坛seq556" width="554" height="200" /></a></p>
<p>这样就可以捕获到所有的目录啦！</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>  open  FH_OUT ,&quot;&gt;bioinformatics.csv&quot;;</p>
<p> $total_pages=571;</p>
<p>  foreach (1..$total_pages){</p>
<p>         my $url = URI-&gt;new(&quot;http://seqanswers.com/forums/forumdisplay.php?&quot;);</p>
<p>         my($f,$page) = (18,$_);#</p>
<p>         $url-&gt;query_form(</p>
<p> 'f' =&gt; $f,</p>
<p> 'order'=&gt; 'desc',</p>
<p>         'page' =&gt; $page,</p>
<p>         );</p>
<p>&amp;get_each_index($url,'FH_OUT');</p>
<p>print $url.&quot;\n&quot;;</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>        $tmp=$tree-&gt;find_by_attribute(&quot;id&quot;,&quot;threadbits_forum_18&quot;);</p>
<p>        next unless $tmp;</p>
<p>        my @list_tr=$tmp-&gt;find_by_tag_name('tr');</p>
<p>        shift @list_tr;shift @list_tr;shift @list_tr;shift @list_tr;shift @list_tr;</p>
<p>        foreach  (@list_tr) {</p>
<p>                my @list_td=$_-&gt;find_by_tag_name('td');</p>
<p>                #print $_-&gt;as_text;</p>
<p>                next unless @list_td&gt;4;</p>
<p>                my $brief=$list_td[2]-&gt;attr('title');</p>
<p>                my $title=$list_td[2]-&gt;find_by_tag_name('a')-&gt;as_text();</p>
<p>                my $href=$list_td[2]-&gt;find_by_tag_name('a')-&gt;attr('href');</p>
<p>                my $author=$list_td[3]-&gt;as_text();</p>
<p>                #print $handle  &quot;$base$href\t$title\t$author\t$brief\n&quot;;</p>
<p>print $handle  &quot;$base$href\t$title\t$author\n&quot;;</p>
<p>        }</p>
<p>}</p>
<p>[/perl]</p>
<p>帖子列表如下：</p>
<p>共17109个帖子。</p>
<p><a href="http://www.bio-info-trainee.com/wp-content/uploads/2015/03/生信常用论坛seq2414.png"><img class="alignnone size-full wp-image-330" src="http://www.bio-info-trainee.com/wp-content/uploads/2015/03/生信常用论坛seq2414.png" alt="生信常用论坛seq2414" width="554" height="424" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.bio-info-trainee.com/328.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
