# doas攻击:通过爬虫进行网页访问
import urllib.request
url = "http://www.baidu.com"
# 访问网页,然后保存到request变量当中
request = urllib.request.Request(url)
# 打开这个变量
response = urllib.request.urlopen(request)
print(response)
# 解码打开
html = response.read().decode()
print(html)
# 匹配术:正则表达式
# 爬取照片
import requests
# 发送请求
response = requests.get('https://www.baidu.com/img/sug_bd.png')
#保存
with open("b.png",'wb') as f:
f.write(response.content)
import requests
url = "http://t.weather.sojson.com/api/weather/city/101010100"
response = requests.get(url)
d = response.json()
dd = "城市:" + d['cityInfo']['city'] + '\n' + '温度:'+d['data']['wendu']
print(dd)
# 数字012321 字符串"" 列表[] 字典{} 元组() 布尔表达式 True False
Alex -初学python
最新推荐文章于 2020-12-18 13:13:31 发布