啥是原神我也不是很清楚
只知道女朋友最近很喜欢
所以给她整了点表情包还有全角色图+语音包
不过分,一点都不过分
源码资料电子书:点击此处跳转文末名片获取
import re
from selenium import webdriver
import time
import requests
driver = webdriver.Chrome()
def drop_down():
for x in range(1, 27, 3):
time.sleep(1)
j = x / 27 # 1/9 3/9 5/9 9/9
js = 'document.documentElement.scrollTop = document.documentElement.scrollHeight * %f' % j
driver.execute_script(js)
lis = driver.find_elements_by_css_selector('.dgControl_list li .iuscp')
page = 1
for li in lis:
try:
img_url = li.find_element_by_css_selector('.mimg').get_attribute('src')
title = li.find_element_by_css_selector('.b_dataList a').get_attribute('title')
title = re.sub(r'[\/"<>*?|\n]', '', title)
img_content = requests.get(url=img_url).content
with open('img//' + title + str(page) + '.jpg', mode='wb') as f:
f.write(img_content)
print(title, img_url)
page +=1
这里特意留了一个小bug,诶嘿~
源码资料电子书:点击此处跳转文末名片获取
import requests
import re
import execjs
所有角色的:
1. 右键点击检查(开发者工具)
2.刷新网页,找准对应数据
url = 'https:///main/character/liyue?char=1'
html_data = requests.get(url).text
print(html_data)
源码资料电子书:点击此处跳转文末名片获取
随便搜索网站内包含内容:“南十字”
使用正则表达式匹配数据内容
js_text = re.findall('window.__NUXT__=(.*);', html_data)[0]
html_data = requests.get(url).text
js_text = re.findall('window.__NUXT__=(.*);', html_data)[0]
result = execjs.eval(js_text)
此时会出现编码问题
加指定编码
import subprocess
from functools import partial
subprocess.Popen = partial(subprocess.Popen, encoding="utf-8")
再次运行,无报错
使用pprint查看数据结构
pprint.pprint(result)
返回网页查看我们需要的内容
打印所需数据
charList = result['data'][0]['charList']
for char in charList:
cover1 = char['cover1']
title = char['title']
intro = char['intro']
audio_list = char['cv'][0]['audio']
print(title, intro, cover1, audio_list)
import requests
import re
import execjs
url = 'https://python学习交流:903971231/main/character/liyue?char=1'
html_data = requests.get(url).text
js_text = re.findall('window.__NUXT__=(.*);', html_data)[0]
result = execjs.eval(js_text)
# pprint.pprint(result)
charList = result['data'][0]['charList']
for char in charList:
cover1 = char['cover1']
title = char['title']
intro = char['intro']
audio_list = char['cv'][0]['audio']
print(title, intro, cover1, audio_list)