Python之旅 3·数据爬虫常见问题

解决python爬虫requests.exceptions.SSLError: HTTPSConnectionPool(host=‘XXX‘, port=443)问题

方法:先检查pip有没安装cryptography,pyOpenSSL,certifi要是没有先安装
  pip install cryptography
  pip install pyOpenSSL
  pip install certifi

连接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))

爬虫所需包

方法:

import urllib.request
from bs4 import BeautifulSoup
import pymysql
import datetime
import random
import gzip

 

 

 

 

Python之旅 3·数据爬虫常见问题

上一篇:算法入门 - 链表的实现及应用(Java版本)


下一篇:Leetcode 209. 长度最小的子数组 双指针