#获取数据库链接
        connection = pymysql.connect(
            host='localhost',
            user='root',
            password='root',
            db='wikiurl',
            charset='utf8mb4'
        )
        try:
            #获取会话指针
            with connection.cursor() as cursor:
              #创建SQL语句
              sql = "insert into `urls` (`urlname`,`urlhref`) values(%s,%s)"
              #执行sql语句
              cursor.execute(sql,(url.get_text(),"https://en.wikipedia.org" + url["href"]))
              #提交
              connection.commit()

        finally:
              #关闭
              connection.close()

结果
将数据传入mysql

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-24
  • 2021-10-31
  • 2021-11-20
  • 2021-10-25
  • 2021-08-13
猜你喜欢
  • 2022-01-20
  • 2021-11-07
  • 2021-12-03
  • 2022-02-11
  • 2021-11-01
相关资源
相似解决方案