爬取网站美女照片
# -*- coding: utf-8 -*-
import requests
from bs4 import BeautifulSoup
import os
import random
import csv
import time
urls=[]
urlls=[]
datas=[]
i=0
def Download(name,url,dirname):
dir=dirname+"//"
path=os.path.join(dir,name)
response=requests.get(url)
try:
with open(path,"wb") as f:
f.write(response.content)
f.close()
global i
i=i+1
except Exception as e:
print(e)
#获取每一个分类的URL和名字
def Geturl():
resp=requests.get("http://www.27270.com/ent/meinvtupian/")
resp.encoding="gbk" #设置网页编码
html=resp.text
soup=BeautifulSoup(html,"html.parser")
divSoup1=soup.find("div",attrs={"id":"NewTagListBox"})
aas=divSoup1.find_all("a")
for a in aas:
tup=(a