Python批量获取下载的Pixiv图片的作者

经评论区的提醒,决定为本站所有用到的图片添加艺术家的版权信息。

奈何当初只保存了图片,怎么办呢?以下是解决办法:

1
2
3
4
5
6
7
8
9
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
36
import os, requests, re
#from lxml import etree

proxy = r'http://127.0.0.1:10809'
# proxy = r'http://your_user:your_password@your_proxy_url:your_proxy_port'
proxies = {
'http': proxy,
'https': proxy
}

def N2Id(name):
Id = name[:8]
print(Id)
return Id

def getHtml(Id):
url = f'https://www.pixiv.net/artworks/{Id}'
return requests.get(url, proxies=proxies , verify=False)

Aid = re.compile(r'"authorId":"(\d+?)"')
Ana = re.compile(r'"userName":"(.+?)"')
def Id2U(Id):
#html = etree.HTML(getHtml(Id).text)
text = getHtml(Id).text
st = text.find(f'{Id}_p0.jpg')
if st == -1: st = text.find(f'{Id}_p0.png')
if st == -1: print(text)
text = text[st:st+500]
## print(text)
## print(Aid.findall(text))
authorId = Aid.findall(text)[0]
userName = Ana.findall(text)[0]
return f'<a href="https://www.pixiv.net/users/{authorId}" target="_blank" rel="nofollow">{userName}</a>'

Us = (Id2U(N2Id(name)) for name in os.listdir(r'./gallary'))


Python批量获取下载的Pixiv图片的作者
https://b.limour.top/445.html
Author
Limour
Posted on
November 26, 2020
Licensed under