1.安装requests-----》pip install requests
import requests
r = requests.get("http://www.weather.com.cn/weather/101280601.shtml")
r.encoding="utf-8"
print(r.text)
会出现如下所示的效果
有的网站禁止爬虫,这样的话 需要模拟浏览器发送请求,在谷歌浏览器输入chrome://version
import requests
//加上header
headers = {"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.80 Safari/537.36"
}
r = requests.get("https://www.tianqi.com/shenzhen/life.html",headers=headers)
r.encoding="utf-8"
print(r.text)
这样就能爬取了!!!