파 이 썬 기반 소재 사이트 오디 오 파일

기본 환경 설정
  • python 3.6
  • pycharm
  • requests
  • parsel

  • 관련 모듈 pip 설치 가능
    대상 페이지


    요청 페이지
    
    import requests
    url = 'https://www.tukuppt.com/peiyue/zonghe_0_0_0_0_0_0_1.html'
     headers = {
       'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36',
     }
     response = requests.get(url=url, headers=headers)
    웹 페이지 분석,데이터 추출
    
    import parsel
    selector = parsel.Selector(response.text)
    urls = selector.css('#audio850995 source::attr(src)').getall()
    titles = selector.css('.b-box .info .title::text').getall()
    data = zip(urls, titles)
    for i in data:
      mp3_url = 'https:' + i[0]
      title = i[1]
    데이터 저장
    
    def download(url, title):
      response = requests.get(url=url, headers=headers)
      path = 'D:\\python\\demo\\      \\    \\' + title + '.mp3'
      with open(path, mode='wb') as f:
        f.write(response.content)


    이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.

    좋은 웹페이지 즐겨찾기