今天百度首页的GIF动画很可爱,就想着用才学的爬虫爬取一下,虽然直接点击“图片另存为”就可以了
import requests
import urllib
class Gif():
def __init__(self):
self.url = "https://www.baidu.com/"
self.headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36",
"Cookie": "PSTM=1532507219; BIDUPSID=744FC8169D5FCF96B0D52E877D986196; BD_UPN=12314753; sug=3; sugstore=0; ORIGIN=0; bdime=0; BAIDUID=8BCA01F5566A428695A7C6746F2D14A7:SL=0:NR=10:FG=1; BDORZ=B490B5EBF6F3CD402E515D22BCDA1598; BD_HOME=0; H_PS_PSSID=26522_1444_21102_26920_22073; BD_CK_SAM=1; PSINO=1; H_PS_645EC=3961PEn4beT4VXC2wPutsiLXiqojMMzqrsQ8hyXLbiKRvaGmLMcSxRklREQ; locale=zh"}
def parse_url(self):
response = requests.get(self.url,headers = self.headers)
return response.content.decode("utf-8")
def get_image_download(self,html_str):
urllib.request.urlretrieve("https://www.baidu.com/img/dong_76e40b922934aed1b944458c58a8c0ef.gif","1.gif")
def run(self):
html_str = self.parse_url()
self.get_image_download(html_str)
if __name__ == '__main__':
c=Gif()
c.run()
可能明天这个代码就不行了,emmmmm