2011-12-24 12 views
1
<div id="song_html" class="show1"> 
    <div class="left"> 
     <!-- info mp3 here --> 
     3.88 mb 
    </div> 
    <div id="right_song"> 
     <div style="font-size: 15px;"> 
      <b>Beatles - Hey Jude mp3</b></div> 
     <div style="clear: both;"> 
     </div> 
     <div style="float: left;"> 
      <div style="float: left; height: 27px; font-size: 13px; padding-top: 2px;"> 
       <div style="float: left; width: 27px; text-align: center;"> 
        <a href="javascript:void(0)" onclick="showPlayer(161498180, 'b7f231500894c321c0a7739802edff16965eb111', 'beatles', 'hey+jude')" 
         rel="nofollow" id="lk161498180" class="play_now">Play</a></div> 
       <div style="margin-left: 8px; float: left;"> 
        <a href="http://dc109.4shared.com/img/1038702204/8ffe01b/dlink__2Fdownload_2FxAdbDSb4_3Ftsid_3D20111224-60034- 
        aa918a50/preview.mp3" rel="nofollow" target="_blank" style="color: green;">Download</a></div> 
       <div style="margin-left: 8px; float: left;"> 
        <a href="javascript:void(0)" onclick="showEmbed(161498180, 
        'b7f231500894c321c0a7739802edff16965eb111')" rel="nofollow" id="em161498180" class="embed"> 
         Embed</a></div> 
       <div style="margin-left: 8px; float: left;"> 
        <a href="http://www.ringtonematcher.com/go/?sid=WDLL&artist=beatles&song=hey+jude" 
         rel="nofollow" target="_blank" style="color: red;" title="Send Beatles - Hey Jude Ringtone to your Cell"> 
         Send Ringtone</a></div> 
       <div style="clear: both;"> 
       </div> 
      </div> 
      <div id="player161498180" style="float: left; margin-left: 10px;" class="player"> 
      </div> 
     </div> 
     <div style="clear: both;"> 
     </div> 
    </div> 
    <div style="clear: both;"> 
    </div> 
</div> 

私は「http://dc109.4shared.com/img/1038702204/8ffe01b/dlink__2Fdownload_2FxAdbDSb4_3Ftsid_3D20111224-60034-aa918a50/preview.mp3」リンクを取得する方法を知っているのが大好きです。ボタンからURLを取り出す方法は?

私は他のフォーラムや人々を何度も尋ねましたが、私はまだ理解していない/働いていません。

他のクラスがあるので、私はクラス "show1"を通してそれを得る必要があります。

+0

Javascript/jQueryを使用して検索したいですか? – Virendra

+0

この質問をするには、本当にそのHTMLをすべて投稿する必要がありましたか?それでも同じ問題がある小さなサンプルを作成できませんでしたか? –

答えて

1

これを頻繁に行う場合は、サードパーティ(オープンソース)のライブラリHtmlAgilityPackを使用して、XPath(オンラインで多くのリソースがある)を使用して価値を得ることができます。

私はURLを取得するには、次の使用します(HtmlWeb.Loadを使用してページをダウンロードすることにより)HtmlDocumentを作成すると:

String theLink = myDoc.DocumentNode.SelectSingleNode("//div[@class='show1']//a[.='Download']").Attributes["href"].Value;

+0

HtmlAgilityPackへのリンクはありますか?また、私はそれを使用する場合、ユーザーもそれをダウンロードする必要がありますか? – Andrew

+0

http://htmlagilitypack.codeplex.com/。 DLLとして使用するので、ユーザーはそれを必要とします(ただし、インストールファイルに含めることも、ILMergeを使用することもできます)。http://www.microsoft.com/downloads/en/details.aspx?id= 17630 - 私はこのオプションの経験はありませんが)あなたは実行可能ファイルと同じディレクトリにDLLを置くこともできます。 –

0

を唯一のユニークなものがテキストである場合、あなたはそれを行うことができます

var href = $('a:text("Download")').attr('href'); 

希望、これはあなたがHTML-パールシーを使用してそれを得る行うことができます

0

に役立ちます:jQueryのを使用した方法ngをHtmlAgilityPackとします。

簡単な例:

var doc = new HtmlAgilityPack.HtmlDocument(); 
doc.LoadHtml(html); 
var nodes = doc.DocumentNode.SelectNodes("//a[.='Download']"); 
var link = nodes[0].Attributes["href"].Value; 

私はあなたがHTMLを取得するためWebClientクラスからDownloadStringメソッドを使用することができ、あなたは4sharedページからこのHTMLを取得していると信じています。

APIを使用すると、より簡単な方法でそれを行うことができます。

+0

他の方法のAPIの使い方は? – Andrew

関連する問題