方法一:代码查看
通过python获取网页的链接url,返回码,以及相关的信息
#对反爬虫网页,可以设置一些headers信息,模拟成浏览器取访问网站import urllib.requesturl="https://www.baidu.com/"file=urllib.request.urlopen(url)print('获取当前url:',file.geturl() )print('file.getcode,HTTPResponse类型:',file.getcode )print('file.info 返回当前环境相关的信息:' ,file.info())
输出结果:
D:\工具\pythonTools\CatchTest1101\venv\Scripts\python.exe D:/工具/pythonTools/CatchTest1101/venv/test/test110204.py获取当前url: https://www.baidu.com/file.getcode,HTTPResponse类型: <bound method HTTPResponse.getc