1.待获取信息(MySQL):
2.核心代码:
import pymysql
if __name__ == "__main__":
config = {
'host':'localhost',
'port':3306,
'user':'localhost',
'password':'123456',
'database':'hx_users',
}
connection = pymysql.connect(**config) # 创建连接
cur = connection.cursor() # 创建游标
cur.execute("select id,title from hupu_datas") #查询rk_jcxx表所需的字段数据
result = cur.fetchall()
print("正在爬取",result)
cur.close() # 关闭游标
connection.close() # 关闭连接
3.输出结果: