webpage 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,5 @@
1
+ require 'uri'
2
+ require 'nokogiri'
1
3
  def fuzzy_uri(uri)
2
4
  begin
3
5
  URI(uri).normalize
@@ -5,6 +7,24 @@ def fuzzy_uri(uri)
5
7
  URI(URI.encode(uri)).normalize
6
8
  end
7
9
  end
10
+ class URI::Generic
11
+ def equal?(target)
12
+ origin = self.normalize.component_ary
13
+ target = target.normalize.component_ary
14
+ origin.pop
15
+ target.pop
16
+ return origin == target
17
+ end
18
+ end
19
+
20
+ __END__
21
+ class Nokogiri::XML::Node
22
+ def method_missing(name)
23
+ p name
24
+ return nil unless key?(name.to_s)
25
+ get(name.to_s)
26
+ end
27
+ end
8
28
  class Mechanize::Page::Link
9
29
  def uri
10
30
  @uri ||= if @href then
data/lib/webpage.rb CHANGED
@@ -1,49 +1,92 @@
1
1
  #coding:UTF-8
2
- require 'mechanize'
3
2
  require 'webpage/common'
4
3
  class Webpage
5
4
  def initialize(body,options={})
6
5
  raise ArgumentError 'body cannot be empty' unless body
7
6
  @body = body
8
7
  @options = options
9
- @body = @body.force_encoding(@options[:encoding]).encode("UTF-8", :invalid => :replace, :undef => :replace, :replace => "") if @options.has_key?:encoding
8
+ #@body = @body.force_encoding(@options[:encoding]).encode("UTF-8", :invalid => :replace, :undef => :replace, :replace => "") if @options.has_key?:encoding
10
9
  @nokogiri = Nokogiri::HTML(@body)
10
+ if options.has_key?:uri
11
+ @uri = fuzzy_uri(@options[:uri])
12
+ raise '@uri should be absolute' unless @uri.absolute?
13
+ @host = @uri.host
14
+ end
15
+ @domain = options[:domain]
16
+ end
17
+ def title
18
+ @nokogiri.xpath("//title").text
11
19
  end
12
20
 
13
21
  def text
14
- return @nokogiri.xpath("//text()").text
22
+ @nokogiri.xpath("//text()").text
15
23
  #return body.gsub(/<\/?[^>]*>/, "")
16
24
  end
17
25
 
26
+ def canonical
27
+ self['canonical'].first['href']
28
+ end
29
+
30
+ def [] (tag)
31
+ return @nokogiri.xpath("//link[@rel='canonical']") if tag == 'canonical'
32
+ return @nokogiri.xpath("//meta[@name='keywords']") if tag == 'keywords'
33
+ return @nokogiri.xpath("//meta[@name='description']") if tag == 'description'
34
+ return @nokogiri.xpath("//#{tag}")
35
+ end
36
+
37
+ def nodes_with(key)
38
+ @nokogiri.xpath("//@#{key}")
39
+ end
40
+
18
41
  def keywords
19
42
  @keywords ||= @nokogiri.xpath("//meta[@name='keywords']").map{|meta|meta['content']}.flatten.join.split(',')
20
- #content = meta.attributes["content"].value unless meta.nil?
21
- #return content.split(',') unless content.nil?
22
43
  end
23
-
44
+
24
45
  def description
25
46
  @description ||= @nokogiri.xpath("//meta[@name='description']").map{|meta|meta['content']}.flatten.join
26
47
  end
27
-
48
+
28
49
  def links
29
50
  @links ||= %w(a area).map do |tag|
30
51
  @nokogiri.xpath("//#{tag}")
31
52
  end.flatten
32
53
  end
54
+
33
55
  def link_to?(target_uri)
34
- links.any?{|link|make_href_absolute(link['href']) == target_uri}
56
+ links.any?{|link|
57
+ #p make_href_absolute(link['href'].to_s)
58
+ fuzzy_uri(link['href'].to_s).equal? fuzzy_uri(target_uri)
59
+ }
60
+
61
+ #links.any?{|link|fuzzy_uri(make_href_absolute(link['href'].to_s)).equal? fuzzy_uri(target_uri)}
35
62
  end
63
+
36
64
  def link_to_host?(host)
37
65
  links.any?{|link|fuzzy_uri(link['uri'].to_s).host == host}
38
66
  end
39
67
 
68
+ def links_to_different_host
69
+ raise '@host cannot be empty' unless @host
70
+ @links_to_different_host ||= links.delete_if do|link|
71
+ #fuzzy_uri(link['href'].to_s).host == @host or fuzzy_uri(link['href'].to_s).host.to_s.empty?
72
+ uri = fuzzy_uri(link['href'].to_s)
73
+ uri.host.to_s.empty? or uri.host == @host
74
+ end
75
+ end
76
+
77
+ def links_to_different_domain
78
+ raise '@domain cannot be empty' unless @domain
79
+ @links_to_different_domain ||= links.delete_if do|link|
80
+ uri = fuzzy_uri(link['href'].to_s)
81
+ uri.host and uri.host.end_with?@domain
82
+ end
83
+ end
84
+
40
85
  private
41
86
  def make_href_absolute(href)
42
87
  href = fuzzy_uri(href.to_s)
43
88
  return href.to_s if href.absolute?
44
- raise 'need :basepath in options when initialize' unless @options.has_key?:basepath
45
- basepath = fuzzy_uri(@options[:basepath])
46
- raise 'basepath should be absolute' unless basepath.absolute?
47
- URI.join(basepath,href)
89
+ raise 'need :uri in options when initialize' unless @uri
90
+ URI.join(@uri,href)
48
91
  end
49
92
  end
data/spec/sample ADDED
@@ -0,0 +1,507 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>
2
+ <head>
3
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
4
+ <title>甜菜根_互动百科</title>
5
+ <meta name="description" content="甜菜根-甜菜根,也叫作根菾菜、红菜头,亦有称“红甜菜”的,但与红甜菜实为不同变种。研究发现它可以帮助肌肉利用氧气,效果约提升3%,持续30分钟,可能成为运动员的秘密武器。-tiancaigen">
6
+ <meta name="keywords" content="甜菜根,,健康,植物,自然">
7
+ <meta name="author" content="甜菜根">
8
+ <meta http-equiv="Pragma" content="no-cache">
9
+ <meta http-equiv="Cache-Control" content="no-cache">
10
+ <meta http-equiv="Expires" content="0">
11
+ <link href="http://static.hudong.com/wiki/popwindow.css" rel="stylesheet" type="text/css">
12
+ <link href="http://www.huimg.cn/public/loginbox/css/loginbox110621.css" rel="stylesheet" type="text/css" media="all">
13
+ <link href="http://www.huimg.cn/entry/css/entry120711.css" rel="stylesheet" type="text/css" media="all">
14
+ <link rel="canonical" href ="http://www.hudong.com/wiki/甜菜根"/>
15
+ <script type="text/javascript" src="http://www.huimg.cn/lib/jquery-1.3.2.js"></script>
16
+ <script type="text/javascript" src="http://www.huimg.cn/public/js/headandfoot20120713.js"></script>
17
+ <script type="text/javascript" src="http://www.huimg.cn/lib/jquery.dialog-0.8.min.js?1101"></script>
18
+ <script type="text/javascript" src="http://www.huimg.cn/lib/jquery.autocomplete.search-ext-bing-0.1-min.js"></script>
19
+ <script type="text/javascript" src="http://apps.hudong.com/js/commonlogin/loadlogin.js"></script>
20
+ <script type="text/javascript" src="http://www.huimg.cn/entry/js/viewdocnew120720.js"></script>
21
+
22
+
23
+ <script type="text/javascript" language="javascript">
24
+ document.domain="hudong.com";
25
+ var HD_HEAD_OPTION;
26
+ function editdoc(){
27
+ try{
28
+ editpower();
29
+ return false;
30
+ }catch(e){
31
+ }
32
+ }
33
+ $(document).ready(function() {
34
+ HD_HEAD_OPTION = {
35
+ location : $("div#max-head")
36
+ };
37
+ loadLogin('8', 'loggingnews');
38
+ try{
39
+ auto_complete_crossdomain_general("input[name=q][autocomplete]", 3, "doc", 457, {customOffsetTop:2,customOffsetLeft:-3},true);
40
+ }catch(e){}
41
+ });
42
+ </script>
43
+ <script type="text/javascript" src="http://i.hudong.com/snspace/js/userNoticeInfoEntrance.js"></script>
44
+
45
+ </head>
46
+ <body>
47
+ <div id="hd_ad_doc_2"> </div>
48
+ <div id="max-head">
49
+ <div class="link-black" id="navigation">
50
+ <ul class="l">
51
+ <li><a href="http://www.hudong.com">互动百科</a></li>
52
+ <li><a href="http://i.hudong.com/chat.do">新知社</a></li>
53
+ <li><a href="http://www.baike.com/">百科网</a></li>
54
+ <li><a href="http://kaiyuan.hudong.com/">HDWIKI建站</a></li>
55
+ <li class="bor-no"><a href="http://about.hudong.com/m/index.html">移动</a></li>
56
+ </ul>
57
+ <ul id="loggingnews" class="r"><li>正在加载中...</li></ul>
58
+ </div>
59
+ <div id="navigations"><ul>
60
+ <li><a href="http://www.hudong.com/?prd=citiaozhengwen_daohangtiao" target="_self">首页</a></li>
61
+ <li><a href="http://top.hudong.com/?prd=citiaozhengwen_daohangtiao" target="_self">IN词</a></li>
62
+ <li><a href="http://tupian.hudong.com/?prd=citiaozhengwen_daohangtiao" target="_self">图片</a></li>
63
+ <li><a href="http://group.hudong.com/?prd=citiaozhengwen_daohangtiao" target="_self">小组</a></li>
64
+ <li><a href="http://task.hudong.com/?prd=citiaozhengwen_daohangtiao" target="_self">任务</a></li>
65
+ <li><a href="http://www.hudong.com/giftshop/index.html?prd=citiaozhengwen_daohangtiao" target="_self">积分换礼</a></li>
66
+ <li><a href="http://www.hudong.com/fenlei/?prd=citiaozhengwen_daohangtiao" target="_self">百科分类</a></li>
67
+ <li><a href="http://z.hudong.com/" target="_self">知识官网</a></li>
68
+ </ul></div>
69
+ <div class="top-img">
70
+ <p class="qqzdbk"><a href="http://fenleisuoyin.hudong.com/">全球</a>最大<a href="http://xinjiancitiao.hudong.com/">中文</a><a href="http://citiaorenwu.hudong.com/">百科</a></p>
71
+ <a id="logo" href="http://www.hudong.com/"><img src="http://www.huimg.cn/public/images/logo110901.gif" alt="互动百科 - 全球最大中文百科网站" title="互动百科 - 全球最大中文百科网站"></a><div class="nav-search navstt">
72
+ <p><iframe scrolling="no" frameborder="0" src="http://www.hudong.com/tuijian/index_top_hot.html" style="width: 290px; height: 20px;" marginheight="0" marginwidth="0"> </iframe></p>
73
+ <ul class="search-tablist">
74
+ <li class="selected"><a href="javascript:;" action="searchselecthref" selectflag="doc">词条</a></li>
75
+ <li><a href="javascript:;" action="searchselecthref" selectflag="picture">图片</a></li>
76
+ </ul>
77
+ <div class="search-panel">
78
+ <input type="text" class="l w-388" name="q" autocomplete="off"><input type="button" class="entry-button gray6" value="进入词条">
79
+ </div>
80
+ <input type="button" class="search-button" value="">
81
+ </div>
82
+ </div>
83
+ </div>
84
+ <div class="l w-640">
85
+ <div id="hd_ad_doc_7"> </div>
86
+ <div class="content-h1">
87
+ <div class="r">
88
+ <div class="mark scoreAction s5">
89
+
90
+
91
+ <a value="1" title="1分,一般" alt="1分,一般" class="star1"></a>
92
+ <a value="2" title="2分,一般" alt="2分,一般" class="star2"></a>
93
+ <a value="3" title="3分,不错" alt="3分,不错" class="star3"></a>
94
+ <a value="4" title="4分,不错" alt="4分,不错" class="star4"></a>
95
+ <a value="5" title="5分,丰富" alt="5分,丰富" class="star5"></a>
96
+ <a value="6" title="6分,丰富" alt="6分,丰富" class="star6"></a>
97
+ <a value="7" title="7分,专业" alt="7分,专业" class="star7"></a>
98
+ <a value="8" title="8分,专业" alt="8分,专业" class="star8"></a>
99
+ <a value="9" title="9分,权威" alt="9分,权威" class="star9"></a>
100
+ <a value="10" title="10分,权威" alt="10分,权威" class="star10"></a>
101
+ </div>
102
+
103
+ <div name="newTips" class="no_score" style="display:none"><p>词条评分功能上线!欢迎体验~</p><em></em></div>
104
+ <a href="#" class="quanweipingshen">权威评审</a>
105
+ </div>
106
+ <h1>甜菜根</h1>
107
+ </div>
108
+ <div class="clear"></div>
109
+ <div class="place">
110
+ <p id="openCatp" class="l" style="display:none">开放分类:<a target="_blank" title="健康" href="http://fenlei.hudong.com/%E5%81%A5%E5%BA%B7/?prd=zhengwenye_left_kaifangfenlei">健康</a><a target="_blank" title="植物" href="http://fenlei.hudong.com/%E6%A4%8D%E7%89%A9/?prd=zhengwenye_left_kaifangfenlei">植物</a><a target="_blank" title="自然" href="http://fenlei.hudong.com/%E8%87%AA%E7%84%B6/?prd=zhengwenye_left_kaifangfenlei">自然</a></p>
111
+ <p class="r"><a class="editterm" href="/editdocauth/%E7%94%9C%E8%8F%9C%E6%A0%B9" onclick="return editdoc();">编辑词条</a><a id="share_link" class="partake" href="#">分享</a></p>
112
+ <div id="share" style="display: none;">
113
+ <span> </span><ul>
114
+ <li><a id="xinzhisheshare1" class="xinzhishe" href="#"><em></em>新知社</a></li>
115
+ <li><a class="sinaminblog" href="#"><em></em>新浪微博</a></li>
116
+ <li><a class="tencent" href="#"><em></em>腾讯微博</a></li>
117
+ <li><a class="renrenlink" href="#"><em></em>人人网</a></li>
118
+ <li><a class="qqzone" href="#"><em></em>QQ空间</a></li>
119
+ <li><a class="wangyiminblog" href="#"><em></em>网易微博</a></li>
120
+ <li><a class="repaste2kaixin001link" href="#"><em></em>开心001</a></li>
121
+ <li><a class="tianya" href="#"><em></em>天涯</a></li>
122
+ <li><a class="fetion" href="#"><em></em>飞信空间</a></li>
123
+ <li><a class="msn" href="#"><em></em>MSN</a></li>
124
+ <li><a class="shuoke" href="#"><em></em>移动说客</a></li>
125
+ </ul>
126
+ </div>
127
+ </div>
128
+ <div class="clear"></div>
129
+ <div id="unifyprompt" class="information">
130
+ <p id="unifypromptone" style="display:none"> </p>
131
+ <div class="summary">
132
+ <div class="img img_r">
133
+ <a target="_blank" href="http://tupian.hudong.com/a2_57_80_20300000336297134362804719923_jpg.html" title="甜菜根"><img src="http://a2.att.hudong.com/57/80/20300000336297134362804719923_140.jpg" alt="甜菜根" title="甜菜根"></a><strong>甜菜根</strong>
134
+ </div><p>甜菜根,也叫作根菾菜、红菜头,亦有称“红甜菜”的,但与<a href='http://www.hudong.com/wiki/%E7%BA%A2%E7%94%9C%E8%8F%9C' target='_blank'>红甜菜</a>实为不同变种。研究发现它可以帮助肌肉利用<a href='http://www.hudong.com/wiki/%E6%B0%A7%E6%B0%94' target='_blank'>氧气</a>,效果约提升3%,持续30分钟,可能成为运动员的秘密武器。</p><span><a action="editsummaryhref" href="javascript:void(0);" onclick="editSummary();return false;">编辑摘要</a></span>
135
+ </div>
136
+ </div>
137
+ <div class="dianping zoom"><ul class="zoom">
138
+ <li>
139
+ <span><a uiden="zAQNWX1leVEFcXnsB" class="yonghu" target="_blank" href="http://i.hudong.com/profile.do?useriden=zAQNWX1leVEFcXnsB">莫小夏</a></span><span><em class="yinhao_l"></em>美国福克斯新闻报道,甜菜根汁可能成为运动员的秘密武器,研究发现它可以帮助肌肉利用氧气,效果约提升3%,持续30分钟。<em class="yinhao_r"></em></span>
140
+ </li>
141
+ <li><a href="#" class="r expertCommentA">我来点评</a></li>
142
+ </ul></div>
143
+ <fieldset id="catalog" class="l">
144
+ <p>目录</p>
145
+ <dl id="full" class="l-he22">
146
+ <dd><a href="#1">1 简介</a></dd>
147
+ <dd><a href="#3">2 形态特征</a></dd>
148
+ <dd><a href="#5">3 生态习性</a></dd>
149
+ <dd><a href="#7">4 繁殖培育</a></dd>
150
+ <dd><a href="#13">5 营养功效</a></dd>
151
+ <dd id="doccatalog_show" class="full"><a href="#"><em> </em></a></dd>
152
+ </dl>
153
+ <dl id="full-all" style="display:none;">
154
+ <dd><a href="#1">1 简介</a></dd>
155
+ <dd><a href="#3">2 形态特征</a></dd>
156
+ <dd><a href="#5">3 生态习性</a></dd>
157
+ <dd>
158
+ <a href="#7">4 繁殖培育</a><ol>
159
+ <li><a href="#9">4.1 繁殖技术</a></li>
160
+ <li><a href="#11">4.2 栽培技术</a></li>
161
+ </ol>
162
+ </dd>
163
+ <dd><a href="#13">5 营养功效</a></dd>
164
+ <dd><a href="#15">6 实验研究</a></dd>
165
+ <dd class="full"><a id="doccatalog_hide" href="#"><em> </em></a></dd>
166
+ </dl>
167
+ </fieldset>
168
+ <!--google_ad_section_start-->
169
+ <div id="content">
170
+ <div class="content_h2 bac_no">
171
+ <h2 class="mar-t10">
172
+ <a id="bjbd" href="#" secId="1" target="_self"> </a><a name="1"> </a>甜菜根 -
173
+ 简介</h2>
174
+ </div>
175
+ <div class="img img_r" id="changeTheId-wrap-img-0" style="width: 300px; "><a title="甜菜根的叶梗" href="http://tupian.hudong.com/a3_52_68_01300000356220128011688847408_jpg.html" target="_blank"><img id="changeTheId-img-0" title="甜菜根的叶梗" alt="甜菜根的叶梗" src="http://a3.att.hudong.com/52/68/01300000356220128011688847408_s.jpg" /></a><strong>甜菜根的叶梗</strong></div><p>甜菜根(BEETR00T),又称甜菜头,红菜头,由生长在<a class="innerlink" title="地中海" href="http://www.hudong.com/wiki/%E5%9C%B0%E4%B8%AD%E6%B5%B7" target="_blank">地中海</a>沿岸的一种名叫海甜菜根的野生植物演变而来。甜菜根红焰如火,又被称为火焰菜。 <br /><br />甜菜根作为食物有着悠久的历史,它所含矿物化合物和植物化合物是甜菜根特有的,这些化合物能抗感染,增加细胞含氧量,治疗血液病,肝病及免疫系统功能紊乱。甜菜根这种蔬菜中含有对人体非常好的<a class="innerlink" title="叶酸" href="http://www.hudong.com/wiki/%E5%8F%B6%E9%85%B8" target="_blank">叶酸</a>,而这种元素是预防<a class="innerlink" title="贫血" href="http://www.hudong.com/wiki/%E8%B4%AB%E8%A1%80" target="_blank">贫血</a>的重要物质之一,并且还有抗癌、防止<a class="innerlink" title="高血压" href="http://www.hudong.com/wiki/%E9%AB%98%E8%A1%80%E5%8E%8B" target="_blank">高血压</a>、<a class="innerlink" title="老年痴呆症" href="http://www.hudong.com/wiki/%E8%80%81%E5%B9%B4%E7%97%B4%E5%91%86%E7%97%87" target="_blank">老年痴呆症</a>的作用。 </p><p>在古代英国的传统医疗方法中,甜菜根是治疗血液疾病的重要药物,被誉为“生命之根”<sup><a href="#hdtop_1" name="hdend_1" title="百姓美食网:甜菜根">[1]</a></sup> </p><div class="content_h2"><h2 class="mar-t10">
176
+ <a id="bjbd" href="#" secId="3" target="_self"> </a><a name="3"> </a>甜菜根 -
177
+ 形态特征</h2>
178
+ </div>
179
+ <p></p>直根系。下胚轴与主根上部膨大形成肉质根,内部具多层的形成层,每一层形成层向内分生木质部,向外分生韧皮部,形成维管束环,环与环之间为薄壁细胞。肉质根有球形、扁圆形、卵圆形、纺锤形、圆锥形等,以扁圆形品质最好。茎短缩。中卵圆形,有光泽,具长叶柄,均为紫红色。
180
+ <p>圆锥花序,完全花,萼片4-5,花瓣5,黄色,雄蕊4-5。异花授粉,授粉后苞片及<a class="innerlink" title="花萼" href="http://www.hudong.com/wiki/%E8%8A%B1%E8%90%BC" target="_blank">花萼</a>宿存,包裹着果实。种子圆形,千粒重13.26克。 </p><div class="content_h2"><h2 class="mar-t10">
181
+ <a id="bjbd" href="#" secId="5" target="_self"> </a><a name="5"> </a>甜菜根 -
182
+ 生态习性</h2>
183
+ </div>
184
+ <p></p><div class="img img_r" id="changeTheId-wrap-img-1" style="width: 300px; "><a title="新鲜甜菜根的切面" href="http://tupian.hudong.com/a2_66_69_01300000356220128011696736524_jpg.html" target="_blank"><strong><img id="changeTheId-img-1" title="新鲜甜菜根的切面" alt="新鲜甜菜根的切面" src="http://a2.att.hudong.com/66/69/01300000356220128011696736524_s.jpg" /></strong></a><strong>新鲜甜菜根的切面</strong></div><p>根甜菜为二年生植物。第一年进行营养生长,形成产品器官,长成肥大的肉根甜菜质根。第二年抽薹开花结籽。根甜菜的适应性很强,较耐寒,也较耐热。生长适温为12~26℃。苗期耐霜冻。通过春化阶段的适温为2~6℃,30~80天完成。通过春化阶段后,在20~25℃的适温和长日照条件下抽薹、开花、结籽。   </p><p>根甜菜适于富含有机质、疏松、湿润、排水良好的壤土、砂壤土或黏壤土栽培。适宜的出为6.5~7,不适于酸性土壤,微碱性土壤仍可生长发育。对土壤溶液浓度反应不敏感,幼苗期能忍受1%的<a class="innerlink" title="土壤溶液" href="http://www.hudong.com/wiki/%E5%9C%9F%E5%A3%A4%E6%BA%B6%E6%B6%B2" target="_blank">土壤溶液</a>浓度,较大的植株能忍受1.5%的土壤溶液浓度。 </p><p>肉质根膨大期需要较多的水分供应,应保持湿润的土壤条件。生育前期需要较多的<a class="innerlink" title="氮" href="http://www.hudong.com/wiki/%E6%B0%AE" target="_blank">氮</a>,中后期需要较多的<a class="innerlink" title="钾" href="http://www.hudong.com/wiki/%E9%92%BE" target="_blank">钾</a>,对<a class="innerlink" title="磷" href="http://www.hudong.com/wiki/%E7%A3%B7" target="_blank">磷</a>的需要较均匀。</p><div class="content_h2"><h2 class="mar-t10">
185
+ <a id="bjbd" href="#" secId="7" target="_self"> </a><a name="7"> </a>甜菜根 -
186
+ 繁殖培育</h2>
187
+ </div>
188
+ <a name="9"> </a><h3>繁殖技术</h3><p>第一年主要进行营养生长,形成产品<a class="innerlink" title="器官" href="http://www.hudong.com/wiki/%E5%99%A8%E5%AE%98" target="_blank">器官</a>。在低温下通过春化阶段后,翌春于适温(20-25℃)和长日照下抽薹、开花、结子。其生育周期与其他根菜类蔬菜相似。</p><p>通过春化阶段的适温为2-6℃,30-80天完成。春季播种过早,当年也会抽薹开花。根甜菜适应性强,较耐寒,也较耐热,生长适温为12-26℃。 </p><a name="11"> </a><h3>栽培技术</h3><p>适应性很强,既耐寒又耐热,因而播种期不严格。一般可行春播和秋播。   </p><p>华北地区,春播宜早,在3月上中旬当10厘米深处地温稳定在8℃以上时就可露地直播,5月下旬收获。如果利用保护地育苗,可于2月上旬播种,3月中下旬定植,4月下旬即可收获。</p><p>华北地区及长江流域可行秋播,一般在7~8月播种,10月下旬至11月上旬收获。</p><p>在高纬度地区,一般是春末播种,初秋收获,一年一茬。<sup><a href="#hdtop_2" name="hdend_2" title="女人伊甸园,甜菜根">[2]</a></sup> </p><div class="content_h2"><h2 class="mar-t10">
189
+ <a id="bjbd" href="#" secId="13" target="_self"> </a><a name="13"> </a>甜菜根 -
190
+ 营养功效</h2>
191
+ </div>
192
+ <div class="img img_r" id="changeTheId-wrap-img-2" style="width: 300px; "><a title="研究发现甜菜根对于人体的健康有着明显的促进作用" href="http://tupian.hudong.com/a2_72_75_01300000356220128011755451377_jpg.html" target="_blank"><img id="changeTheId-img-2" title="研究发现甜菜根对于人体的健康有着明显的促进作用" alt="研究发现甜菜根对于人体的健康有着明显的促进作用" src="http://a2.att.hudong.com/72/75/01300000356220128011755451377_s.jpg" /></a><strong>研究发现甜菜根对于人体的健康有着明显的促进作用</strong></div><p>甜菜根中还含有<a class="innerlink" title="碘" href="http://www.hudong.com/wiki/%E7%A2%98">碘</a>的成分,对预防甲状腺肿以及防治<a class="innerlink" title="动脉粥样硬化" href="http://www.hudong.com/wiki/%E5%8A%A8%E8%84%89%E7%B2%A5%E6%A0%B7%E7%A1%AC%E5%8C%96">动脉粥样硬化</a>都有一定疗效。</p><p>甜菜根的块根及叶子含有一种甜菜碱成分,是其它蔬菜所未有的,它具有和<a class="innerlink" title="胆碱" href="http://www.hudong.com/wiki/%E8%83%86%E7%A2%B1">胆碱</a>、<a class="innerlink" title="卵磷脂" href="http://www.hudong.com/wiki/%E5%8D%B5%E7%A3%B7%E8%84%82">卵磷脂</a>生化药理功能,是新陈代谢的有效调节剂,能加速人体对蛋白的吸收改善肝的功能。</p><p>甜菜根中还含有一种<a class="innerlink" title="皂角" href="http://www.hudong.com/wiki/%E7%9A%82%E8%A7%92" target="_blank">皂角</a>甙类物质,它有把肠内的胆固醇结合成不易吸收的混合物质而排出。</p><p>甜菜根中还含有相当数量的镁元素,有调节软化血管的硬化强度和阻止预言血管中形成血栓,对治疗高血压有重要作用。</p><p>甜菜根中还含有大量的<a href="http://www.hudong.com/wiki/%E7%BA%A4%E7%BB%B4%E7%B4%A0" class="innerlink" title="纤维素" target="_blank">纤维素</a>和<a href="http://www.hudong.com/wiki/%E6%9E%9C%E8%83%B6" class="innerlink" title="果胶" target="_blank">果胶</a>成分,据研究发现具有一种抗胃溃疡病的因子功能。在医疗实践中还有下泻功能可消除腹中过多水分,缓解腹胀。由于含有铁、铜、锰等元素,还能治疗贫血及作风等病。<sup><a href="#hdtop_1" name="hdend_1" title="百姓美食网:甜菜根">[1]</a></sup> <br /></p><div class="content_h2"><h2 class="mar-t10">
193
+ <a id="bjbd" href="#" secId="15" target="_self"> </a><a name="15"> </a>甜菜根 -
194
+ 实验研究</h2>
195
+ </div>
196
+ <p>2011年,《运动训练医学和科学》杂志刊登英国一项研究发现,喝甜菜根汁可以提高自行车运动员竞技成绩。<sup><a href="#hdtop_3" name="hdend_3" title="科学网,甜菜根汁助提升运动耐力 增强肌肉心脏工作效率11_07/04/7417443_0.shtml">[3]</a></sup> 英国科学家分析指出,甜菜根汁的诸多好处都与其中富含的亚硝酸盐物质不无关系。该物质一旦进入人体即可扩张<a class="innerlink" title="血管" href="http://www.hudong.com/wiki/%E8%A1%80%E7%AE%A1" target="_blank">血管</a>,加速向肌肉及大脑的<a href="javascript:linkredwin('输氧量');" class="link_red" title="输氧量" target="">输氧量</a>,使肌肉和大脑的输氧量达到最大值<sup><a href="#hdtop_4" name="hdend_4" title="半岛新闻,研究发现喝甜菜根汁可提高运动员耐力,2011-07-04">[4]</a></sup> 。</p><p>多项测试结果发现,甜菜根汁中的<a href="http://www.hudong.com/wiki/%E4%BA%9A%E7%A1%9D%E9%85%B8%E7%9B%90" class="innerlink" title="亚硝酸盐" target="_blank">亚硝酸盐</a>可以提高<a class="innerlink" title="肌肉" href="http://www.hudong.com/wiki/%E8%82%8C%E8%82%89" target="_blank">肌肉</a>和心脏工作效率。这项研究首次揭示了甜菜根汁及其中富含的亚硝酸盐对模拟竞技运动的积极作用。其研究结果表明,喝甜菜根汁特别有助于提高耐力型竞技项目成绩。</p><p>另外,喝甜菜根汁的受益者不仅包括专业或业余运动员,而且包括老年和体弱人群,给这些人群提供更多能量,走路更有劲,更顺利完成日常比较费劲的任务。不仅如此,早前期研究还发现,喝甜菜根汁还有助于降低高血压和防止<a class="innerlink" title="老年痴呆症" href="http://www.hudong.com/wiki/%E8%80%81%E5%B9%B4%E7%97%B4%E5%91%86%E7%97%87" target="_blank">老年痴呆症</a>。<sup><a href="#hdtop_4" name="hdend_4" title="半岛新闻,研究发现喝甜菜根汁可提高运动员耐力,2011-07-04">[4]</a></sup> </p></div>
197
+ <!--google_ad_section_end-->
198
+ <div id="hd_ad_doc_3"> </div>
199
+ <div class="wenxian_app">
200
+ <link href="http://www.huimg.cn/hudong/entry/widget/wenxian/css/wenxianapp120509.css" rel="stylesheet" type="text/css">
201
+ <div class="h3tit"><h3>相关文献</h3></div>
202
+ <ul>
203
+ <li>
204
+ <span class="wfimg" title="万方数据">万方数据</span>期刊论文<a href="http://d.wanfangdata.com.cn/Periodical_zwyyyflxb200602015.aspx" target="_blank" title="磷营养水平对不同基因型甜菜根磷酸酶活性的效应" onclick="StatVirtualTraffic(document.referrer,window.location,'stat_hdstat_onclick_wanfang_wenxian')">磷营养水平对不同基因型甜菜根磷酸酶活性的效应</a><span>
205
+ -
206
+ 植物营养与肥料学报
207
+ -
208
+ </span><span>2006</span><span>12</span><span>
209
+ (
210
+ 2
211
+ )
212
+ </span>
213
+ </li>
214
+ <li>
215
+ <span class="wfimg" title="万方数据">万方数据</span>期刊论文<a href="http://d.wanfangdata.com.cn/Periodical_spyjykf201012030.aspx" target="_blank" title="苹果-甜菜根冻茶的工艺优化" onclick="StatVirtualTraffic(document.referrer,window.location,'stat_hdstat_onclick_wanfang_wenxian')">苹果-甜菜根冻茶的工艺优化</a><span>
216
+ -
217
+ 食品研究与开发
218
+ -
219
+ </span><span>2010</span><span>31</span><span>
220
+ (
221
+ 12
222
+ )
223
+ </span>
224
+ </li>
225
+ <li>
226
+ <span class="wfimg" title="万方数据">万方数据</span>期刊论文<a href="http://d.wanfangdata.com.cn/Periodical_zgtcty200604001.aspx" target="_blank" title="不同基因型甜菜根形态和解剖学研究" onclick="StatVirtualTraffic(document.referrer,window.location,'stat_hdstat_onclick_wanfang_wenxian')">不同基因型甜菜根形态和解剖学研究</a><span>
227
+ -
228
+ 中国甜菜糖业
229
+ -
230
+ </span><span>2006</span><span>
231
+ (
232
+ 4
233
+ )
234
+ </span>
235
+ </li>
236
+ </ul>
237
+ </div>
238
+ <div id="figure" class="zoom">
239
+ <h3>附图</h3>
240
+ <span class="more"><a name="_figurea">&nbsp;</a><a href="javascript:void(0)" id="addFigure" style="display:none;">上传图片</a></span>
241
+ </div>
242
+ <div id="fodder" class="zoom"><h3>
243
+ <span class="r gray9">为本词条添加<a target="_blank" href="http://v.hudong.com/videocenter/initadd?docTitle=%E7%94%9C%E8%8F%9C%E6%A0%B9">视频</a>和<a target="_blank" href="http://tupian.hudong.com/zutu/createZutuView?docTitle=%E7%94%9C%E8%8F%9C%E6%A0%B9">组图</a></span>相关影像</h3></div>
244
+ <div class="relevantinfo">
245
+ <dl class="reference bor-no">
246
+ <dt>注释与参考:</dt>
247
+ <dd>
248
+ <span>[1]</span><a href="#hdend_1" name="hdtop_1">^</a>百姓美食网:甜菜根<input name="refrenceurlinput" type="text" class="tag_input" value="http://meishi.88838.com/l/608" onclick="this.select();" readonly>
249
+ </dd>
250
+ <dd>
251
+ <span>[2]</span><a href="#hdend_2" name="hdtop_2">^</a>女人伊甸园,甜菜根<input name="refrenceurlinput" type="text" class="tag_input" value="http://www.77hh.com/fitness/tiancaigen/" onclick="this.select();" readonly>
252
+ </dd>
253
+ <dd>
254
+ <span>[3]</span><a href="#hdend_3" name="hdtop_3">^</a>科学网,甜菜根汁助提升运动耐力 增强肌肉心脏工作效率11_07/04/7417443_0.shtml<input name="refrenceurlinput" type="text" class="tag_input" value="http://tech.ifeng.com/discovery/detail_2011_07/04/7417443_0.shtml" onclick="this.select();" readonly>
255
+ </dd>
256
+ <dd>
257
+ <span>[4]</span><a href="#hdend_4" name="hdtop_4">^</a>半岛新闻,研究发现喝甜菜根汁可提高运动员耐力,2011-07-04<input name="refrenceurlinput" type="text" class="tag_input" value="http://news.bandao.cn/news_html/201107/20110704/news_20110704_1418305.shtml" onclick="this.select();" readonly>
258
+ </dd>
259
+ <dd class="refdd">美国福克斯新闻:甜菜根成奥运会运动员秘密武器?2012<input readonly type="text" name="refrenceurlinput" value="http://www.hjenglish.com/new/p411564/" onclick="this.select();">
260
+ </dd>
261
+ <dd class="refdd">中国甜菜:甜菜根重与含糖率相关关系的研究;1995<input readonly type="text" name="refrenceurlinput" value="http://www.cqvip.com/qk/90784x/19951/1974951.0.html" onclick="this.select();">
262
+ </dd>
263
+ </dl><dl class="quote" id="show_quote" style="display:block;"><dt id="show_quote_dt">
264
+ <span class="l">被引用:</span><span class="l gray normal">甜菜根已被如下媒体引用
265
+ </span><a href="javascript:void(0)" id="editDocQuoteLink" class="r">我来补充</a>
266
+ </dt>
267
+ <dd id="edit_quote" style="display:none;">
268
+ <p>媒体:<input maxlength="60" id="edit_quote_media" type="text" size="15" class="input-textarea"></p>
269
+ <p>标题:<input maxlength="128" id="edit_quote_title" type="text" size="40" class="input-textarea"></p>
270
+ <p>URL:<input maxlength="128" id="edit_quote_link" type="text" size="20" class="input-textarea"></p>
271
+ <p>作者:<input maxlength="64" id="edit_quote_author" type="text" size="10" class="input-textarea"></p>
272
+ <p>日期:<input maxlength="10" id="edit_quote_date" type="text" size="10" class="input-textarea"></p>
273
+ <a class="l" href="javascript:void(0)" onclick="saveDocQuote()">保存</a><a class="l" href="javascript:void(0)" onclick="editDocQuoteCancel()">取消</a>
274
+ </dd>
275
+ </dl>
276
+ <dl id="show_tag" style="display:block;">
277
+ <dt>
278
+ <span class="l">开放分类:</span><a href="javascript:void(0)" class="r completetaghref">我来补充</a>
279
+ </dt>
280
+ <dd><a href="http://fenlei.hudong.com/%E5%81%A5%E5%BA%B7/?prd=zhengwenye_left_kuozhan_kaifangfenlei">健康</a></dd>
281
+ <dd><a href="http://fenlei.hudong.com/%E6%A4%8D%E7%89%A9/?prd=zhengwenye_left_kuozhan_kaifangfenlei">植物</a></dd>
282
+ <dd><a href="http://fenlei.hudong.com/%E8%87%AA%E7%84%B6/?prd=zhengwenye_left_kuozhan_kaifangfenlei">自然</a></dd>
283
+ </dl>
284
+ <dl style="display:none;" id="edit_tag">
285
+ <dt id="edit_tag_dt"><span class="l">开放分类:</span></dt>
286
+ <dd>
287
+ <input type="text" class="input-textarea" maxlength="20" value="健康" name="tag" onblur="this.setAttribute('value',this.value);"> <a href="javascript:void(0)" onclick="removeTag(this)" id="_removeTag">[删除]</a>
288
+ </dd>
289
+ <dd>
290
+ <input type="text" class="input-textarea" maxlength="20" value="植物" name="tag" onblur="this.setAttribute('value',this.value);"> <a href="javascript:void(0)" onclick="removeTag(this)" id="_removeTag">[删除]</a>
291
+ </dd>
292
+ <dd>
293
+ <input type="text" class="input-textarea" maxlength="20" value="自然" name="tag" onblur="this.setAttribute('value',this.value);"> <a href="javascript:void(0)" onclick="removeTag(this)" id="_removeTag">[删除]</a>
294
+ </dd>
295
+ </dl>
296
+ <dl id="show_thesaurus" style="display:none;"><dt id="show_thesaurus_dt">
297
+ <span class="l">同义词:</span><a name="show_thesaurus_test"></a></dt></dl>
298
+ <dl style="display:none;z-index:11;" id="edit_thesaurus"><dt id="thesaurus_edit_dt"><span class="l">同义词:</span></dt></dl>
299
+ </div>
300
+ <p class="place-bottom zoom">
301
+
302
+ <span class="fl"><a href="#" id="recommendhref"><strong id="recommendnum"></strong><em id="recommendinfo">本词条对我有帮助</em></a></span>
303
+ <span>分享到:<a id="xinzhisheshare2" class="xinzhishe" href="#"></a><a class="tencent" href="#"></a><a class="sinaminblog" href="#"></a><a class="shuoke" href="#"></a><a class="wangyiminblog" href="#"></a><a class="renrenlink" href="#"></a><a class="tianya" href="#"></a><a class="repaste2kaixin001link" href="#"></a><a class="msn" href="#"></a><a class="qqzone" href="#"></a><a class="fetion" href="#"></a></span>
304
+ <a id="bootomtiwen" href="javascript:void(0)" class="editterm">我要提建议</a>
305
+
306
+ </p>
307
+ <p class="point l-he22 descriptionP">互动百科的词条(含所附图片)系由网友上传,如果涉嫌侵权,请与客服联系,我们将按照法律之相关规定及时进行处理。如需转载,请注明来源于www.hudong.com。</p>
308
+ <iframe scrolling="no" frameborder="0" id="commentIframeId" marginwidth="0" width="100%" marginheight="0" src=""> </iframe><input name="type" type="hidden" value="doc"><input name="doc_title" id="doc_title" type="hidden" value="甜菜根"><input name="docidencry" id="docidencry" type="hidden" value="uAwgHUUNYW1hWW1sH"><input name="_loginstate" id="_loginstate" type="hidden" value="0">
309
+ </div>
310
+ <div class="r w-300">
311
+ <div id="hd_ad_doc_4"> </div>
312
+ <div class="rightdiv zhuanjia">
313
+ <h3>权威专家</h3>
314
+ <a href="#" class="more askToExpertA">向专家提问</a><div class="w100">
315
+ <div class="pic"><a target="_blank" href="http://i.hudong.com/profile.do?useriden=zAQNWX1leVEFcXnsB"><img id="firstExpertImg" src="http://www.huimg.cn/entry/images/50loading.gif" width="50px" height="50px"></a></div>
316
+ <div class="text">
317
+ <h2><a id="firstExpertA" uiden="zAQNWX1leVEFcXnsB" href="http://i.hudong.com/profile.do?useriden=zAQNWX1leVEFcXnsB" target="_blank" class="yonghu bold">莫小夏</a></h2>
318
+ <p id="firstExpertP" class="gray6"></p>
319
+ </div>
320
+ </div>
321
+ </div>
322
+ <div class="rightdiv cooperation cooperation_t">
323
+ <h3>WIKI热度</h3>
324
+ <ol>
325
+ <li>创建者:<span><a target="_blank" uiden="SZXFndWV6VA1QVVlj" href="http://i.hudong.com/profile.do?useriden=SZXFndWV6VA1QVVlj&prd=citiao_right_jibenxinxi_chuangjianzhe" class="yonghu">黄于道</a></span>
326
+ </li>
327
+ <li>编辑次数:<span>20次</span> <a href="http://www.hudong.com/wikdoc/sp/qr/history/list.do?doc_title=%E7%94%9C%E8%8F%9C%E6%A0%B9&prd=citiao_right_jibenxinxi_lishibanben" target="_blank">历史版本</a>
328
+ </li>
329
+ <li>参与编辑人数:<span>6</span>位</li>
330
+ <li>最近更新时间:2012-07-31 15:49:40</li>
331
+ </ol>
332
+ </div>
333
+ <div class="rightdiv cooperation cooperation_b">
334
+ <h3>贡献光荣榜</h3>
335
+ <a target="_blank" class="more" href="http://www.hudong.com/wikdoc/sp/qr/history/editorlist.do?doc_title=%E7%94%9C%E8%8F%9C%E6%A0%B9&prd=zhengwenye_left_jibenxinxi_xiezuozhe">更多</a><ul>
336
+ <li><p><a uiden="ddncDAFtRA3RXAH1y" href="http://i.hudong.com/profile.do?useriden=ddncDAFtRA3RXAH1y&prd=zhengwenye_zuixinxiezuozhe" class="yonghu">下自成奚</a></p></li>
337
+ <li><p><a uiden="mZH10agFZbWINdFZk" href="http://i.hudong.com/profile.do?useriden=mZH10agFZbWINdFZk&prd=zhengwenye_zuixinxiezuozhe" class="yonghu">海鸥99</a></p></li>
338
+ <li><p><a uiden="MZH10agFZZmQCf1hg" href="http://i.hudong.com/profile.do?useriden=MZH10agFZZmQCf1hg&prd=zhengwenye_zuixinxiezuozhe" class="yonghu">陈小蓓</a></p></li>
339
+ <li><p><a uiden="LGgdcWgJBBwxXBHQd" href="http://i.hudong.com/profile.do?useriden=LGgdcWgJBBwxXBHQd&prd=zhengwenye_zuixinxiezuozhe" class="yonghu">汪河</a></p></li>
340
+ <li><p><a uiden="ARVtRXEUDE0QFB1NG" href="http://i.hudong.com/profile.do?useriden=ARVtRXEUDE0QFB1NG&prd=zhengwenye_zuixinxiezuozhe" class="yonghu">张焕容</a></p></li>
341
+ </ul>
342
+ </div>
343
+ <div id="editmore" style="display:none;">此词条还可添加
344
+ &nbsp;
345
+ </div>
346
+ <div id="docinfotemplettable" class="module rightdiv">
347
+ <h3>生物</h3>
348
+ <a class="more" onclick="perfectinfotempletdata('life')" href="#">编辑</a>
349
+ <table class="table">
350
+ <tbody>
351
+ <tr>
352
+ <td class="a-c p-tb10" colspan="2">
353
+ <a target="_blank" href="http://tupian.hudong.com/a2_00_98_20300000336297134362989431740_jpg.html">
354
+ <img src="http://a2.att.hudong.com/00/98/20300000336297134362989431740_140.jpg"/>
355
+ </a>
356
+ </td>
357
+ </tr>
358
+ <tr>
359
+ <td align="right">中文学名:</td>
360
+ <td style="width:190px;">甜菜根</td>
361
+ </tr>
362
+ <tr>
363
+ <td align="right">中文别名:</td>
364
+ <td style="width:190px;">糖萝卜、甜菜头、红菜头、根甜菜、紫菜头</td>
365
+ </tr>
366
+ <tr>
367
+ <td align="right">英文名:</td>
368
+ <td style="width:190px;">beetroot</td>
369
+ </tr>
370
+ <tr>
371
+ <td align="right">界:</td>
372
+ <td style="width:190px;">植物界</td>
373
+ </tr>
374
+ <tr>
375
+ <td align="right">科:</td>
376
+ <td style="width:190px;">藜科</td>
377
+ </tr>
378
+ <tr>
379
+ <td align="right">属:</td>
380
+ <td style="width:190px;">甜菜属</td>
381
+ </tr>
382
+ <tr>
383
+ <td align="right">分布:</td>
384
+ <td style="width:190px;">原产地中海沿岸,中国有少量栽培。</td>
385
+ </tr>
386
+ </tbody>
387
+ </table>
388
+ </div>
389
+ <div id="map" class="rightdiv" style="display:none"><h3>地图</h3></div>
390
+ <div id="hd_ad_doc_16"> </div>
391
+ <div id="hd_ad_doc_1"> </div>
392
+ <div class="xgct rightdiv">
393
+ <h3>相关词条</h3>
394
+ <a href="javascript:void(0);" class="more" action="perfectcordocbtn">编辑</a><ul>
395
+ <li><a href="/wiki/%E8%A5%BF%E5%85%B0%E8%8A%B1?prd=citiao_right_xiangguancitiao" target="_blank" title="西兰花">西兰花</a></li>
396
+ <li><a href="/wiki/%E8%98%91%E8%8F%87?prd=citiao_right_xiangguancitiao" target="_blank" title="蘑菇">蘑菇</a></li>
397
+ <li><a href="/wiki/%E5%B0%8F%E8%8B%8F%E6%89%93?prd=citiao_right_xiangguancitiao" target="_blank" title="小苏打">小苏打</a></li>
398
+ <li><a href="/wiki/%E5%92%96%E5%95%A1%E5%9B%A0?prd=citiao_right_xiangguancitiao" target="_blank" title="咖啡因">咖啡因</a></li>
399
+ <li><a href="/wiki/%E8%8A%A5%E6%9C%AB?prd=citiao_right_xiangguancitiao" target="_blank" title="芥末">芥末</a></li>
400
+ <li><a href="/wiki/%E8%8B%A4%E8%93%9D?prd=citiao_right_xiangguancitiao" target="_blank" title="苤蓝">苤蓝</a></li>
401
+ </ul>
402
+ </div>
403
+ <div id="hd_ad_doc_5"> </div>
404
+ <div id="hd_ad_doc_17"> </div>
405
+ </div>
406
+ <input type="hidden" name="doctitle_utf8" id="doctitle_utf8" value="%E7%94%9C%E8%8F%9C%E6%A0%B9"><input name="lock_type" id="lock_type" type="hidden" value="01"><input type="hidden" name="doctitle" id="doctitle" value="甜菜根"><input type="hidden" name="_doc_flag" id="_doc_flag" value=""><input type="hidden" name="_doc_type" id="_doc_type" value="1"><input type="hidden" name="doc_first_image" id="doc_first_image" value="http://a3.att.hudong.com/52/68/01300000356220128011688847408_140.jpg"><input type="hidden" name="docid" id="docid" value="300000999237"><input type="hidden" name="dociden" id="dociden" value="uAwgHUUNYW1hWW1sH"><input type="hidden" name="tagstr" id="tagstr" value="健康,植物,自然"><input type="hidden" name="prethes" id="prethes" value=""><input type="hidden" name="pagetype" id="pagetype" value="doc"><input type="hidden" value="1" name="infotempletcount" id="infotempletcount"><input type="hidden" value="SZXFndWV6VA1QVVlj" name="creatoriden" id="creatoriden"><input type="hidden" name="originalsummarycontent" id="originalsummarycontent" value="甜菜根,也叫作根菾菜、红菜头,亦有称“红甜菜”的,但与红甜菜实为不同变种。研究发现它可以帮助肌肉利用氧气,效果约提升3%,持续30分钟,可能成为运动员的秘密武器。"><input type="hidden" name="xiaoneiallcontent" id="xiaoneiallcontent" value='甜菜根,也叫作根菾菜、红菜头,亦有称“红甜菜”的,但与红甜菜实为不同变种。研究发现它可以帮助肌肉利用氧气,效果约提升3%,持续3... 【<a href="http://www.hudong.com/xiaoNeiConnectSuccess.do?action=show&type=1&url=%E7%94%9C%E8%8F%9C%E6%A0%B9" target="_blank">查看全文</a>】'><input type="hidden" name="kaixin001allcontent" id="kaixin001allcontent" value="甜菜根,也叫作根菾菜、红菜头,亦有称“红甜菜”的,但与红甜菜实为不同变种。研究发现它可以帮助肌肉利用氧气,效果约提升3%,持续30分钟,可能成为运动员的秘密武器。"><input type="hidden" name="hdAdBizId" id="hdAdBizId" value="%E7%94%9C%E8%8F%9C%E6%A0%B9">
407
+
408
+ <script type="text/javascript" src="http://www.huimg.cn/lib/jquery.popMessage.js?1104"></script>
409
+
410
+
411
+
412
+ <script type="text/javascript" src="http://static.tianya.cn/js/share/share2tianya.js"></script>
413
+ <script type="text/javascript" src="http://static.connect.renren.com/js/v1.0/FeatureLoader.jsp"></script>
414
+ <script type="text/javascript" language="javascript">
415
+ var g_user_isexpert = false;
416
+ var preTagstr=document.getElementById('tagstr').value;
417
+ var preThesaurusstr=document.getElementById('prethes').value;
418
+ var doctitle_utf8=document.getElementById('doctitle_utf8').value;
419
+ var pb_url="/unLockDoc.do?doc_title="+doctitle_utf8+"&unlockType=tag";
420
+ </script>
421
+
422
+
423
+
424
+ <div id="index-footer" class="">
425
+ <ul class="t">
426
+ <li><a class="yjfk" href="http://group.hudong.com/help" target="_blank">请提意见</a></li>
427
+ <li><a class="bzzx" href="http://service.hudong.com/" target="_blank">帮助中心</a></li>
428
+ <li>热线:86-10-62303127</li>
429
+ <li><a target="_blank" href="http://www.baike.com/map-article.html" style="color:#666666">每日</a> 7:00-22:00</li>
430
+ </ul>
431
+ <ul class="c">
432
+ <li><a target="_blank" href="http://www.hudong.com/wiki/%E4%BA%92%E5%8A%A8%E7%99%BE%E7%A7%91">关于我们</a></li>
433
+ <li><a target="_blank" href="http://www.hudong.com/hdnews/">新闻中心</a></li>
434
+ <li><a target="_blank" href="http://www.hudong.com/wiki/%E4%BA%92%E5%8A%A8%E5%9C%A8%E7%BA%BF%E6%9C%8D%E5%8A%A1%E5%8D%8F%E8%AE%AE">服务协议</a></li>
435
+ <li><a target="_blank" href="http://open.hudong.com/">互动合作</a></li>
436
+ <li><a target="_blank" href="http://www.hudong.com/zhaopin/index.html">招聘信息</a></li>
437
+ <li><a target="_blank" href="http://www.hudong.com/wiki/%E4%BA%92%E5%8A%A8%E7%99%BE%E7%A7%91%EF%BC%9A%E8%81%94%E7%B3%BB%E6%88%91%E4%BB%AC">联系我们</a></li>
438
+ <li class="bor_no"><a target="_blank" href="http://www.hudong.com/map.htm">站点地图</a></li>
439
+ </ul>
440
+ <p class="b">互动在线 版权所有 Powered by <a target="_blank" href="http://kaiyuan.hudong.com/" class="bold">HDwiki</a> &copy; 2005-2012</p>
441
+ </div>
442
+ <script type="text/javascript" src="http://stat.hudong.com/js/webstat_manage.js"></script>
443
+
444
+
445
+
446
+ <script type="text/javascript" src="http://www.huimg.cn/ads/js/hd.ad1.20120719.js"></script>
447
+ <script type="text/javascript">
448
+ var hudongAdDocOptions = {
449
+ bizType : "doc",
450
+ bizId : $("#hdAdBizId").val(),
451
+ domain : "www.hudong.com",
452
+ adBlockPrefix : "hd_ad_doc_",
453
+ adIframePrefix : "hd_ad_doc_iframe_",
454
+ adLocations : [2, 7, 3, 4, 16, 1, 5, 17, 6],
455
+ adConfigs : [{
456
+ type : "iframe",
457
+ width : 950,
458
+ height : 70,
459
+ style : ""
460
+ }, {
461
+ type : "iframe",
462
+ width : 640,
463
+ height : 60,
464
+ style : "margin-top:10px;"
465
+ }, {
466
+ type : "iframe",
467
+ width : 640,
468
+ height : 60,
469
+ style : ""
470
+ }, {
471
+ type : "iframe",
472
+ width : 300,
473
+ height : 250,
474
+ style : "margin-top:10px;"
475
+ }, {
476
+ type : "iframe",
477
+ width : 300,
478
+ height : 256,
479
+ style : "margin-top:10px;"
480
+ }, {
481
+ type : "iframe",
482
+ width : 300,
483
+ height : 250,
484
+ style : "margin-top:10px;"
485
+ }, {
486
+ type : "iframe",
487
+ width : 300,
488
+ height : 250,
489
+ style : "margin-top:10px;"
490
+ }, {
491
+ type : "iframe",
492
+ width : 300,
493
+ height : 310,
494
+ style : "margin-top:10px;"
495
+ }, {
496
+ type : "script"
497
+ }]
498
+ };
499
+ if (typeof(hudongAdsTemplate) != "undefined" && typeof(hudongAdsTemplate.loadAds) == "function") {
500
+ hudongAdsTemplate.loadAds(hudongAdDocOptions);
501
+ }
502
+ </script>
503
+
504
+
505
+ <script type="text/javascript" src="http://stat.hudong.com/js/webstat_manage_hdga.js"></script>
506
+ </body>
507
+ </html>
data/spec/webpage_spec.rb CHANGED
@@ -1,11 +1,26 @@
1
1
  #coding:UTF-8
2
2
  require 'webpage'
3
- uri = 'http://www.hudong.com/'
4
- to_uri = 'http://123.hudong.com/'
5
- to_host = 'hudong.com'
6
- page = Mechanize.new.get uri
7
- page = Webpage.new(page.body,{:basepath=>uri})
3
+ sample = File.read(File.join(File.dirname(__FILE__),'sample'))
4
+ sample_uri = 'http://www.hudong.com/wiki/甜菜根'
5
+ sample_to_uri = 'http://123.hudong.com/'
6
+ sample_not_to_uri = 'http://1234.hudong.com/'
7
+ sample_to_host = 'hudong.com'
8
+ sample_title = '甜菜根_互动百科'
9
+ sample_h1 = '甜菜根'
10
+ sample_keywords = '甜菜根,,健康,植物,自然'.split(',')
11
+ sample_description = '甜菜根-甜菜根,也叫作根菾菜、红菜头,亦有称“红甜菜”的,但与红甜菜实为不同变种。研究发现它可以帮助肌肉利用氧气,效果约提升3%,持续30分钟,可能成为运动员的秘密武器。-tiancaigen'
12
+ page = Webpage.new(sample,{:uri=>sample_uri,:domain=>'hudong.com'})
13
+ describe URI::Generic do
14
+ it "" do
15
+ URI('http://host1.abc.com/a/b/c?d=e&f=g#frag').should be_equal URI('http://host1.abc.com/a/b/c?d=e&f=g#frag')
16
+ URI('http://host1.abc.com/a/b/c?d=e&f=g#frag').should_not be_equal URI('http://host1.abc.com/a/b/c?f=g&d=e#frag')
17
+ end
18
+ end
8
19
  describe Webpage do
20
+ it "title should be String" do
21
+ page.title.class.should == String
22
+ end
23
+
9
24
  it "text should be String" do
10
25
  page.text.class.should == String
11
26
  end
@@ -13,12 +28,22 @@ describe Webpage do
13
28
  it "links should be an array" do
14
29
  page.links.class.should == Array
15
30
  end
31
+
32
+ it "[] should return class Nokogiri::XML::NodeSet" do
33
+ %w(canonical keywords description).each do |tag|
34
+ page[tag].class.should == Nokogiri::XML::NodeSet
35
+ end
36
+ end
37
+
38
+ it "nodes_with should return an array with elements Nokogiri::XML::NodeSet" do
39
+ page.nodes_with('id').class.should == Nokogiri::XML::NodeSet
40
+ end
16
41
  it "links' elements should be Webpage::Link" do
17
42
  page.links.each do |link|
18
43
  link.class.should == Nokogiri::XML::Element
19
44
  end
20
45
  end
21
-
46
+
22
47
  it "description should be text" do
23
48
  page.description.class.should == String
24
49
  end
@@ -34,26 +59,57 @@ describe Webpage do
34
59
  end
35
60
 
36
61
  it "link_to? should return bool" do
37
- [TrueClass,FalseClass].should include page.link_to?(to_uri).class
62
+ [TrueClass,FalseClass].should include page.link_to?(sample_to_uri).class
38
63
  end
39
64
 
40
65
  it "link_to_host? should return bool" do
41
- [TrueClass,FalseClass].should include page.link_to_host?(to_host).class
66
+ [TrueClass,FalseClass].should include page.link_to_host?(sample_to_host).class
67
+ end
68
+
69
+ it "links_to_different_domain should return Array" do
70
+ page.links_to_different_domain.class.should == Array
71
+ end
72
+
73
+ it "links_to_different_host should return Array" do
74
+ page.links_to_different_host.class.should == Array
42
75
  end
43
76
  end
44
77
 
45
- describe "the instance webpage" do
78
+ describe "the instance webpage of #{sample_uri}" do
79
+ it "title should be #{sample_title}" do
80
+ page.title.should == sample_title
81
+ end
46
82
  it "text should be big enought" do
47
83
  page.text.size.should > 500
48
84
  end
49
85
  it "should has correct description " do
50
- page.description.should == '互动百科是基于中文维基技术(维客,wiki百科)的网络百科全书,是全球最大中文百科网及百科全书。互动百科中文网,助您轻松百科探秘'
86
+ page.description.should == sample_description
87
+ end
88
+ it "should has #{sample_keywords.size} keywords" do
89
+ page.keywords.size.should == sample_keywords.size
90
+ end
91
+ it "should has 40 nodes with property 'id'"do
92
+ page.nodes_with('id').size.should == 92
51
93
  end
52
- it "should has 7 keywords" do
53
- page.keywords.size.should == 9
94
+ it "should has <h1>#{sample_h1}"do
95
+ page['h1'].text.should == sample_h1
96
+ end
97
+ it "should has canonical to #{sample_uri}" do
98
+ page.canonical.should == sample_uri
99
+ end
100
+
101
+ it "should link_to #{sample_to_uri}" do
102
+ page.link_to?(sample_to_uri).should be_true
54
103
  end
55
104
 
56
- it "should link_to #{to_uri}" do
57
- page.link_to?(to_uri).should be_true
105
+ it "should not link_to #{sample_not_to_uri}" do
106
+ page.link_to?(sample_not_to_uri).should be_false
107
+ end
108
+
109
+ it "should has link to " do
110
+ page.links_to_different_host.any?{|link|link['href']}
111
+ end
112
+ it "should has link to" do
113
+ page.links_to_different_domain
58
114
  end
59
115
  end
data/webpage.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{webpage}
3
- s.version = '0.0.6'
3
+ s.version = '0.0.7'
4
4
  s.authors = ["seoaqua"]
5
5
  s.date = %q{2012-07-29}
6
6
  s.description = %q{a tool to extract some basic data from a webpage}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webpage
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -36,6 +36,7 @@ files:
36
36
  - .rspec
37
37
  - lib/webpage.rb
38
38
  - lib/webpage/common.rb
39
+ - spec/sample
39
40
  - spec/spec_helper.rb
40
41
  - spec/webpage_spec.rb
41
42
  - webpage.gemspec