python获取网页源代码
最简单的网页取源(不用模拟浏览器的情况)
1 import requests 2 def getHTML(url): 3 try: 4 r = requests.get(url,timeout=30) 5 r.raise_for_status() 6 r.encoding = 'utf-8' 7 return r.text 8 except: 9 return "" 10 url = "http://baidu.com" 11 print(getHTML(url))