Python抓取网页到本地
代码:
>>> from urllib import request >>> urllib.request.urlretrieve('https://pan.baidu.com/download',r'D:\1.html')
from urllib import request 也可以用 import urllib.request 替换
遇到错误:
错误一:AttributeError: module 'urllib' has no attribute 'request'
解决方法:导入模块的方法错了,把“import urllib” 改成“from urllib import request”
错误二:OSError: [Errno 22] Invalid argument: 'D:\\1.html
解决方法:在保存的路径前用r转义
参考:
https://blog.csdn.net/weixin_36896856/article/details/108016558
https://blog.csdn.net/weixin_33814685/article/details/93901884
from urllib import request