Python爬虫入门之get网页信息并作为文本输出

import requests
import os

kv = {
		"User-agent":"Mozilla/5.0"#模拟浏览器
	}
		

def getHtmlText(url):
	try:
		r = requests.get(url,timeout = 30,headers = kv)
		r.raise_for_status()
		r.encoding = r.apparent_encoding
		return r.text
	except:
		return "ERROR"
		

url = input("Please input the URL!\n")
print(getHtmlText(url))
os.system("pause")


posted @ 2018-02-09 15:43  Assassin_poi君  阅读(712)  评论(0编辑  收藏  举报