拿着网站练手
“https://www.yalayi.com/”
如果大家有这种网址的话,请私信或者评论发我。 (需要正规的 不露点的)
如果大家有vip的话,可以私信发我。

[Python] 纯文本查看 复制代码
|
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
import osimport requestsfrom lxml import etreeimport urlliburl = "https://www.yalayi.com/"resp = requests.get(url)# 会乱码 设置一下编码resp.encoding = "utf-8"html = etree.HTML(resp.text)link = html.xpath("//div[@class='main']/div[3]/div[1]/ul/li/div/a/@href")for item in link: # 拿到 url = "https://www.yalayi.com/" 这个url下面的子url =》 get pictures resp = requests.get(item) resp.encoding = "utf-8" # 再次进入xpath sub_page = etree.HTML(resp.text) # print(resp.text) # get download links download_link = sub_page.xpath("//img[@class='lazy']/@data-original") # make dir if not os.path.exists("pic"): os.mkdir("pic") # name count i = 0 name = sub_page.xpath("//img[@class='lazy']/@alt") for download in download_link: urllib.request.urlretrieve(download, "pic/{}.jpg".format(name[i])) print("%s下载完毕" % name[i]) i += 1 # break |