在這里感謝@靜覓
也學(xué)了一段時間python了,不搞一搞爬蟲有點說不過去了万伤。
然后今天就搞了兩個小爬蟲:(就只是涉及簡單的requests庫的使用和簡單的正則,但那個withopen是copy的呜袁。)
import requests,re#https://movie.douban.com/top250?start=75&filter=for j in range(10): t=str(25*j) url="https://movie.douban.com/top250?start="+t+"&filter=" r=requests.get(url) name=re.findall('(.*?)',r.text)
? ? inq=re.findall('.*?inq.*?>(.*?)',r.text)
? ? for i in range(25):
? ? ? ? #def write_to_json(content):
? ? ? ? ? ? #with open('result.txt', 'a') as f:
? ? ? ? ? ? ? ? #print(type(json.dumps(content)))
? ? ? ? ? ? ? ? #f.write(json.dumps(content, ensure_ascii=False,).encode('utf-8'))
? ? ? ? print(name[i],'\t',point[i],'\t',inq[i])
import requests,rej=0d=['科技','動物','建筑','風(fēng)景','花海','旅游','黑白','自然','大海','高山','折頁']for t in d: url="http://meisu.huaban.com/searchi.php?keyword="+t r=requests.get(url)#r=requests.get("http://meisu.huaban.com/searchi.php?keyword=插畫") img=re.findall('.*?data-original.*?(http.*?=thumbs).*?',r.text) name=re.findall('',r.text)
? ? for i in img:
? ? ? ? j=j+1
? ? #for j in range(1000):
? ? ? ? im=requests.get(i)
? ? #for j in name:
? ? ? ? load='imge1/img'+str(j)+'.jpg'
? ? ? ? with open(load,'wb') as f:
? ? ? ? ? ? f.write(im.content)