SoFunction
Updated on 2024-12-13

python crawling kudougou music charts

In this article, we share the specific code for python crawl cool dog music charts, for your reference, the details are as follows

#coding=utf-8
from pymongo import MongoClient
import time 
import requests 
from lxml import etree 
 
client = MongoClient()      #Connect to mongo
hello =        # Connect to the database
user =          #connection table
 
headers = { 
  'User-Agent': 'Mozilla/5.0 (Android 6.0; Nexus 5 Build/MRA58N)\
  AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Mobile Safari/537.36'} 
 
def get_info(url): 
  '''
  get source,encode,parse,xpath,save
  '''
  response = (url, headers=headers) 
  response = ('utf-8') 
  selector = (response) 
  soup = ('//*[@class="pc_temp_songlist "]/ul//li/a/text()') 
 
  #SaveLocal
  # with open('','a') as f:
    # for i in soup:
      # (('utf-8') + '\n')
 
  # Into the database
  for i in soup:
    ({'song': i})
 
if __name__ == '__main__': 
  urls = ['/yy/rank/home/{}-?from=rank'.format(str(i)) for i in range(1, 24)] 
  for url in urls: 
    print(url) 
    get_info(url)

This is the whole content of this article.