import requests import time headers={"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.25 Safari/537.36 Core/1.70.3741.400 QQBrowser/10.5.3863.400"} url_list=[] r_list=[] html_list=[] url="https://www.baidu.com/s?wd={}&pn={}" sou=input("请输入你想百度的内容") for i in range(10): url_list.append(url.format(sou,i*10)) response=requests.get(url_list[i],headers=headers) r_list.append(response.content.decode("utf-8")) time.sleep(10) with open('html_list{}.html'.format(i),"w",encoding='utf-8') as f: f.write(r_list[i])
评论