美文网首页
网络爬虫(mac)入门 python学习

网络爬虫(mac)入门 python学习

作者: MorningandSun | 来源:发表于2019-07-11 19:50 被阅读0次

    1.下载爬虫软件 charles 破解
    下载地址(附带破解):
    http://www.pc6.com/mac/137987.html
    2.学习软件的使用
    破解+配置:
    https://www.jianshu.com/p/9f4ebde9c518
    3.配置python环境 (其实用java也可以,不过别人用的python)
    下载pycharm(mac上自带有python 但是我还是更新了) 破解的话和其他idea产品类似,网上很多
    下载命令

    brew install python
    

    如果是权限的问题 加上sudo即可
    4.使用第三方框架
    这个确实很坑 通过软件自带的下载或者命令下载 不好使
    解决办法
    (1)根据下面的步骤进入

    image.png image.png

    (2)删除之前的地址,换上下面提供的地址再次进行下载即可


    image.png
      1)[http://mirrors.aliyun.com/pypi/simple/](http://mirrors.aliyun.com/pypi/simple/) 阿里云
    
      2)[https://pypi.mirrors.ustc.edu.cn/simple/ ](https://pypi.mirrors.ustc.edu.cn/simple/%20) 中国科技大学
    
      3) [http://pypi.douban.com/simple/](http://pypi.douban.com/simple/)  豆瓣
    
      4) [https://pypi.tuna.tsinghua.edu.cn/simple/](https://pypi.tuna.tsinghua.edu.cn/simple/) 清华大学
    
      5)  [http://pypi.mirrors.ustc.edu.cn/simple/](http://pypi.mirrors.ustc.edu.cn/simple/) 中国科学技术大学
    

    (3)报错的话 在下图所示中输入


    image.png

    提示中让你输入的一个信任的命令 (具体的找不到了,但是脑袋一抽就去试了下 ,就可以了)
    5.开始爬虫了
    6.python数据库操作 ,其实和idea查不到 ,通过软件右方的dabaes连接mysql 输入数据库参数,创建数据库,表,各参数名即可
    7.数据库的命令操作的工具类

    ##导入的第三方库
    import pymysql
    
    
    
    # 用来操作数据库的类
    class dbutils(object):
        # 类的初始化
    
        def __init__(self):
            self.host = 'localhost'
            self.port = 3306  # 端口号
            self.user = 'root'  # 用户名
            self.password = "12345678"  # 密码
            self.db = "book"  # 库
            self.table = "hotbook"  # 表
    
        # 链接数据库
        def connectMysql(self):
            try:
                self.conn = pymysql.connect(host=self.host, port=self.port, user=self.user,
                                            passwd=self.password, db=self.db, charset='utf8')
                self.cursor = self.conn.cursor()
            except:
                print('connect mysql error.')
    
        # 查询数据
        def queryMysql(self):
            sql = "SELECT * FROM " + self.table
    
            try:
                self.cursor.execute(sql)
                row = self.cursor.fetchone()
                print(row)
    
            except:
                print(sql + ' execute failed.')
    
        # 插入数据
        def insertMysql(self, name, aouther, url,imageurl,textinfo):
            sql = "INSERT INTO " + self.table +"(bookname,oauther,url,imageurl,textinfo)"+ " VALUES(" +"'"+ name+"'"+"," +"'"+ aouther+"'"+ "," +"'"+ url+"'"+ ","+"'"+imageurl+"'" +","+"'"+textinfo+"'"+")"
            try:
                self.cursor.execute(sql)
                self.conn.commit()
            except:
                print(sql + ' execute failed.')
    
        # 更新数据
        def updateMysqlSN(self, name, sex):
            sql = "UPDATE " + self.table + " SET sex='" + sex + "'" + " WHERE name='" + name + "'"
            print("update sn:" + sql)
    
            try:
                self.cursor.execute(sql)
                self.conn.commit()
            except:
                self.conn.rollback()
    
        def closeMysql(self):
            self.cursor.close()
            self.conn.close()
    
    

    插入数据库的sql语句就看各位自己的发挥了 (本人数据库贼烂)

    相关文章

      网友评论

          本文标题:网络爬虫(mac)入门 python学习

          本文链接:https://www.haomeiwen.com/subject/gykjkctx.html