最近开始研究python,就想学习一下爬虫方面的技能,我使用的python3,找了资料,用pycharm运行成功后整理记录一下,
代码如下:
运行结果:#!/usr/bin/python # coding:utf-8 import urllib.request def getHtmlContent(url): request = urllib.request.Request(url) response = urllib.request.urlopen(request) data = response.read() data = data.decode('utf-8') return data def main(): url="https://www.baidu.com" print(getHtmlContent(url)) if __name__ == '__main__': main()