python爬虫第1练url lib
2021/5/3 12:25:25
本文主要是介绍python爬虫第1练url lib,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
'''本代码在mac中测试通过‘’‘ #也可以使用import urllib.request,调用方法时需加上urllib,即以urllib.request开头 from urllib import request #本部分尚不理解,待日后研究 import ssl ssl._create_default_https_context = ssl._create_unverified_context #以上部分可能受ssl验证机制影响,据同学讲在windows下不需要,未实测 #为保密原因,以***隐去部分字符 url='https://www.***.com' headers={'User-Agent':' Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/605.1.15 (KHTML, like Gecko) ********'} '创建对象' req= request.Request(url, headers=headers) '获取响应' res = request.urlopen(req) '读取网页' html=res.read().decode('utf-8') '输出结果' # print(html) with open('firsthtml.html','w',encoding='utf-8') as file_obj: file_obj.write(html)
这篇关于python爬虫第1练url lib的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-08有遇到过吗?同样的规则 Excel 中 比Python 结果大
- 2024-03-30开始python成长之路
- 2024-03-29python optparse
- 2024-03-29python map 函数
- 2024-03-20invalid format specifier python
- 2024-03-18pool.map python
- 2024-03-18threads in python
- 2024-03-14python Ai 应用开发基础训练,字符串,字典,文件
- 2024-03-13id3 algorithm python
- 2024-03-13sum array elements python