1·解决python爬虫requests.exceptions.SSLError: HTTPSConnectionPool(host=’XXX’, port=443)问题
方法:先检查pip有没安装cryptography,pyOpenSSL,certifi要是没有先安装
pip install cryptography
pip install pyOpenSSL
pip install certifi
2·连接MySQL数据库问题
方法:
import pymysql # 建立数据库连接 def getDBConnection(): print(‘***************getDBConnection start‘) host = ‘127.0.0.1‘ port = 3306 user = ‘root‘ password = ‘123‘ db = ‘music‘ charset = ‘utf8‘
DBConnection = pymysql.connect(host=host, port=port, user=user, password=password, db=db, charset=charset) return DBConnection
# 保存音乐信息到数据库中 def saveMusicToDB(m_id, m_name, m_link, m_type, m_singer, m_album, m_click, m_collect): print(‘**********************saveMusicToDB start‘) DBConnection = getDBConnection() print(‘dbconnection=‘ + str(DBConnection)) # 创建 游标 cursor = DBConnection.cursor() sql = ‘insert into orgmusic(m_id,m_name,m_link,m_type,m_singer,m_album,m_click,m_collect) values(%s,%s,%s,%s,%s,%s,%s,%s)‘ cursor.execute(sql, (m_id, m_name, m_link, m_type, m_singer, m_album, m_click, m_collect))
3·爬虫所需包
方法:
import urllib.request from bs4 import BeautifulSoup import pymysql import datetime import random import gzip
我们不是一群默默无闻的码农,而是推进世界进步的开荒者
神龙|纯净稳定代理IP免费测试>>>>>>>>天启|企业级代理IP免费测试>>>>>>>>IPIPGO|全球住宅代理IP免费测试