![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
爬虫
文章平均质量分 59
梦中学逆向
这个作者很懒,什么都没留下…
展开
-
解决fake_useragent.errors.FakeUserAgentError: Maximum amount of retries reached问题
方法一 更新fake_useragent pip3 install -U fake_useragent 方法二 下载fake_useragent.json文件 我的版本是0.1.11,所以下载的就是0.1.11.json 下载地址,提取码是77h3 下载成功后直接将文件放在项目同级目录下 from fake_useragent import USERAGENT location = os.getcwd() + ‘/fake_useragent_0.1.11.json’ ua = UserAge原创 2021-07-07 09:39:37 · 551 阅读 · 4 评论 -
数据持久化的三种方式
csv模块 作用:将爬取的数据存放到本地的csv文件中 使用流程 打开csv文件 初始化写入对象 写入数据(参数为列表) writerow([]):单行写入 writerows((),(),()]:多行写入,一次性写入多行数据 pymysql模块与mysql数据库交互流程 创建数据库连接对象—》db = pymysql.connect(xx,xx,xx,xx) 创建游标对象 —》cursor = db.cursor() 执行sql命令 —》 cursor.execute(sql语句,[xx,xx原创 2021-04-14 17:56:01 · 1498 阅读 · 0 评论 -
urllib使用
请求模块-urllib.request ####### urllib.request.urlopen()方法 urlopen() 作用:向网站发起请求并获取响应对象 参数 url:需要爬取的url地址 timeout:设置等待超时时间,指定时间内未响应抛出异常 响应对象res的方法 获取响应内荣(字节串) res.read() 获取响应内容(字符串) res.read().decode() 返回实际数据的url地址 res.geturl() 获取http响应码原创 2021-04-14 16:57:51 · 73 阅读 · 0 评论