Python 爬取 煎蛋
阿新 • • 發佈:2018-12-21
這個我是拿來參考的
import requests def url_open(url): response = requests.get(url) html = response.content return html url="http://jandan.net/ooxx/" html=url_open(url).decode("utf-8") image_urllist=[] a=html.find("img src=") while a!=-1: b=html.find("jpg",a,a+255) if b!=-1: image_urllist.append("http:"+html[a+9:b+4]) else: b=a+9 a=html.find("img src=",b) count=0 for index,each in enumerate(image_urllist): # filename=each.split("/")[-1] filename=str(count)+".jpg" with open(filename,"wb") as f: img=url_open(each) f.write(img) print(each)if index>3: break count+=1