解决Error occurred during loading data. Trying to use cache server https://fake-useragent.herokuapp.co

问题描述:
爬虫随机生成UA
导最新包,包版本已为最新0.1.11

pip install fake-useragent

执行如下代码并报错

from fake_useragent import UserAgent
ua = UserAgent(cache=False)
print(ua.chrome)

报错信息

Error occurred during loading data. Trying to use cache server https://fake-useragent.herokuapp.com…


解决方法:
查看本地临时路径

import tempfile

a = tempfile.gettempdir()
print(a)

输出

C:\Users\LZX\AppData\Local\Temp

网上获取一个 fake_useragent_0.1.11.json
复制到上述目录中
在这里插入图片描述


运行结果:

from fake_useragent import UserAgent
ua = UserAgent()
print(ua.random)

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1309.0 Safari/537.17

猜你喜欢

转载自blog.csdn.net/weixin_41772761/article/details/120194015
今日推荐