Home > other >  When I python enthusiasts, recently self-study, want to use the following code crawl songs, appear p
When I python enthusiasts, recently self-study, want to use the following code crawl songs, appear p

Time:09-21

The import of re # python regular library
Import requests # python requests library
The import time

SongName=[] # used to store every song name
SongId=[] # used to store every song corresponding digital
# 1 page to download songs here
In the range for n (0, 2) :
# string format n instead of {}
Url="http://www.htqyy.com/top/musiclist/hot? PageIndex={} & amp; PageSize=20 '. The format (n)
Print (url, end='\ n')
# simulation browser requests and get the HTML code
HTML=requests. Get (url)
# use regular expressions to capture digital, (within) to capture content, *? For any content
ResultId=re. The.findall (' sid="(. *?) "& gt; ', HTML, text)
# resultId=re. The.findall (' sid="(. *?) "& gt; ', HTML, text)
# use regular expressions to capture the song
ResultName=re. The.findall (' & lt; A href="https://bbs.csdn.net/topics/. *?" Target="play" title=(. *?) "Sid=". *?"> ', HTML, text)
# into array
SongId. The extend (resultId)
SongName. The extend (resultName)
Print (songId)
Print (songName)
# string formatting m instead of {}
In the range for m (0, len (songId) :
Songurl='{http://f2.htqyy.com/play7/}/mp3/1'. The format (songId [m])
Print (songurl, end='\ n')
Print (' is download the first {} '. The format (m + 1))
# get returns the resource content
The response=requests. Get (songurl). The content
# written in the form of binary file
F=open (' e: \ \ music \ \ {} mp3 '. The format (songName [m]), 'wb)
F.w rite (response)
F. lose ()

http://www.htqyy.com/top/musiclist/hot? PageIndex=0 & amp; PageSize=20
[' 33 ', '62', '58', '261', '55', '1621', '231', '329', '56', '3', '187', '26', '1668', '57', '108', '23', '1430', '591', '176', '34']
[' morning ', '" cucurbit flute', '" soul umbrella', '" The soul of The sounds of nature', '" The hometown of The original landscape', '" The seed of The sun OST "Always"', '" extremely relaxing sleep light music', '" time gone', '" The night's piano five', '" whispers',' "The sundial dream background music (radio) ', '" you smile', '" Annie's wonderland', '" scarborough fair (whistle)', '" shepherd's song', '" The sound of silence', '" The broad sea', '" The Beginning of', '" aesthetic for healing The piano', '" moonlight']
http://f2.htqyy.com/play7/33/mp3/1
Is download 1
Traceback (the most recent call last) :
File "E: \ \ pyhonn \ py_y File tutorial class 2.1 copy source \ \ python creeper. Py", line 32, in & lt; module>
F=open (' e: \ \ music \ \ {} mp3 '. The format (songName [m]), 'wb)
OSError: [22] Errno Invalid argument: 'e: \ \ music \ \ "in the early morning. Mp3'
[Finished in 1.5 s with exit code 1)
[shell_cmd: python - u "E: \ documents \ pyhonn \ py_y crawler tutorial class source \ \ python 2.1 - copy. Py"]
\ [dir: E: \ file pyhonn \ py_y \] python crawler tutorial class source code
[path: E: \ pyhtop \ Scripts \; E: \ pyhtop \; E: \ \ python Scripts \; E: \ \ python; E: \ Anaconda \ Scripts; E: \ Anaconda; E: \ \ python Scripts \; E: \ \ python; C: \ Users \ \ Administrator \ \ AppData \ Local \ designed \ python Python37 \ Scripts \; C: \ Users \ Administrator \ AppData \ Python37 \ \ Local \ designed \ python; E: \ pyhtop \ Scripts \; E: \ pyhtop \; E: \ \ python Scripts \; E: \ \ python; E: \ Anaconda \ Scripts; E: \ Anaconda; E: \ \ python Scripts \; E: \ python \]

CodePudding user response:

More than a song name "


# use regular expressions to capture the song
ResultName=re. The.findall (' & lt; A href="https://bbs.csdn.net/topics/. *?" Target="play" title=(. *?) "Sid=". *?"> ', HTML, text)


Instead of

 
ResultName=re. The.findall (' & lt; A href="https://bbs.csdn.net/topics/. *?" Target="play" title="(. *?) "Sid=". *?"> ', HTML, text)



Such a change, the name, there is no"

CodePudding user response:

Download music is only 2 k, how be to return a responsibility
  • Related