python 爬虫goole主页
import requests url="https://www.google.cn/" def gethtml(url): try: r=requests.get(url) r.raise_for_status() r.encoding="utf-8" print("text内容:",r.text) except: return "Error!" for i in range(20): print(gethtml(url))
运行结果:
import requests url="https://www.google.cn/" def gethtml(url): try: r=requests.get(url) r.raise_for_status() r.encoding="utf-8" print("text内容:",r.text) except: return "Error!" for i in range(20): print(gethtml(url))
运行结果: