Internet, listen to songs, plus a cup of fragrant, really leisurely. When I heard the interest, I naturally wanted to see the lyrics. The music limit website provides lyrics search. I think, can we implement lyrics search in the program as programming enthusiasts? After some study, it was also very simple.
First look at how music limit lyrics search is going. For example, Search Zhang Xueyou's "stealing", I found that the music limit has a lyrics search mode: Just type http://geci.chinamp3.com/related in the IE address bar, / == 心 & Singer_name = Zhang Xuelou
And enter, you can search for lyrics. That is to say, the song name is to be entered at "Zhang Xueyou". In the "stealing", it is a song name, and then you can search. I also tried the songs of other singer, all can be. And I check the source file to find the lyrics to discharge the fixed law in the web page. For example, on the webpage showing the lyrics, there is a fixed "lyrics:", and they are put in one in the source file.
...
between. So when we got all source files, we first look for "lyrics:", if you can't find it, you don't have the lyrics to search on the server; if you find it, remove all the code in front, then look for "
", Just find the first"
", We will clear it and the code behind it, the lyrics are in the remaining code. We know," <"and"> "are paired in the web page. I carefully study the remaining code. It is either lyrics between ">" and "<" or a space. So as long as you remove all "<" and ">" content in the remaining code, you can get lyrics.
How do you search for the source file? There are several controls in VB. This program uses the INET control. Inet has two ways to request the specified data to the server, namely OpenURL and Execute. Their differences are that the former is synchronized, and the latter is asynchronous. In general, using OpenURL is relatively convenient because it can directly assign a variable to a variable directly. But this program only uses Execute, because using OpenURL will have a difficult problem, what is the problem, or leave the reader when you practice.
Start now. Open VB6, create a new project, add an INET control in the toolbox. Draw three text boxes on the form form, named TXT singer, TXT song name and txt lyrics, TEXT attributes are empty, where the attribute of the TXT lyrics Multiline is True, the property scrollbars is 2-Vertical. Add another button and named CMD search, its property caption is a search; finally add an INET control, named INET1.
The detailed code is as follows:
Option expedition
Private Sub CMD Search_click ()
'Request to the server to download the lyrics
Inet1.execute "http://geci.chinamp3.com/relatedgeci.php?song_name=" & TRIM (TXT Song Name) & "&" & "Singer_Name =" & TRIM (TXT Singer), "Get"
End Sub
Private sub inet1_statechanged (Byval State As Integer)
DIM page code $
DIM Temporary Variable $
DIM Location &
IF state = 11 THEN
Msgbox "Error!" Elseif State = 12 THEN
Do 'starts accepting data
Doevents
Temporary variable $ = inet1.getchunk (1024, ICString)
IF LEN (Temporary Variable $) = 0 THEN EXIT DO
Web code $ = web code $ & Temporary Variable $ 'Accepted all data stored in Variable "Webc code $"
Loop
Location & = INSTR (1, web code $, "lyrics:") 'First look for feature words "lyrics:"
IF location & = 0 THEN
'If you didn't find a feature word "lyrics:" Just prove the lyrics that the server is available
MsgBox "The lyrics of this song!"
EXIT SUB
Else
'Analyze the lyrics
'First of all, "lyrics:" in front of "lyrics:"
Webc code $ = right (web code $, LEN (web code $) - (location & - 1))
'Looking for the second feature word "
"Location & = INSTR (1, web code $,"
")
'Take the Special Word
"The following code (including the feature word itself) all remove the web code $ = left (web code $, location & - 1) 'lyrics in the remaining code Do DoEvents location & = INSTR (1, web page code $," <") IF Location & = 0 Then 'If the character cannot be found" <"to prove the entire search has ended temporary variable $ = Temporary Variable $ &" & Web Code $ EXIT Do Else' Find characters "<" Code Interception Save Temporary Variable $ = Temporary Variable $ & "" & Left (web code $, location & - 1) 'Clear the Accepted section and characters "<" from "Webc code $" "<" page code $ = Right (Web code $, LEN (web code $) - Location &) 'Review Character ">" Location & = INSTR (1, web code $, ">")' Find characters> "put it front code included itself All clear web code $ = right (web code $, LEN (web code $) - Location &) End if loop '"Temporary Variable $" stores lyrics, give them all to "TXT lyrics" txt lyrics = temporary variable $ END IF End If End Sub http://www.yzcc.com/2004/11-21/0924938547.html