Last active
May 29, 2022 05:48
-
-
Save XiaoGeNintendo/2bae756dee507ed88547a87a870be434 to your computer and use it in GitHub Desktop.
Touhou R-18 Research Tool Version 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# THIS IS AN EXAMPLE FILE!!! | |
博麗霊夢 | |
霧雨魔理沙 | |
ルーミア | |
チルノ | |
紅美鈴 | |
...... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io.github.bonigarcia.wdm.WebDriverManager | |
import me.tongfei.progressbar.ProgressBar | |
import org.openqa.selenium.By | |
import org.openqa.selenium.PageLoadStrategy | |
import org.openqa.selenium.WebDriver | |
import org.openqa.selenium.chrome.ChromeDriver | |
import org.openqa.selenium.chrome.ChromeOptions | |
import org.openqa.selenium.support.ui.ExpectedConditions | |
import org.openqa.selenium.support.ui.WebDriverWait | |
import java.io.File | |
import java.time.Duration | |
lateinit var driver: WebDriver | |
val res = HashMap<String,Triple<Int,Int,Int>>() | |
const val base="https://www.pixiv.net/ajax/search/artworks/%s" | |
fun findCount(name:String):Int{ | |
driver.get(String.format(base,name)) | |
val json=driver.findElement(By.tagName("body")).text | |
val id1=json.indexOf("\"total\":") | |
val id2=json.indexOf(",",id1) | |
return json.subSequence(id1+"\"total\":".length,id2).toString().toInt() | |
// return driver.findElement(By.className("sc-1pt8s3a-8")).text.toInt() | |
} | |
fun solveChar(char: String){ | |
println("Solving for character: $char") | |
val a1=findCount(char) | |
val a2=findCount("$char R-18") | |
val a3=findCount("$char R-18G") | |
// | |
res[char]=Triple(a1,a2,a3) | |
println("$char $a1 $a2 $a3") | |
} | |
fun login(){ | |
println("Logging in to pixiv") | |
val fs = File("password.txt") | |
val info=fs.readLines() | |
println("Account Info: Usr=${info[0]} Psd=${info[1]}") | |
driver.get("https://accounts.pixiv.net/login") | |
WebDriverWait(driver, Duration.ofHours(1)).until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.className("signup-form__submit"))) | |
val elements=driver.findElements(By.tagName("input")) | |
for(i in elements){ | |
if(i.getAttribute("autocomplete")=="username"){ | |
i.sendKeys(info[0]) | |
}else if(i.getAttribute("autocomplete")=="current-password"){ | |
i.sendKeys(info[1]) | |
} | |
} | |
val enter=driver.findElement(By.className("signup-form__submit")) | |
enter.click() | |
WebDriverWait(driver, Duration.ofHours(1)).until(ExpectedConditions.not(ExpectedConditions.urlContains("login"))) | |
} | |
fun main(){ | |
println("Touhou R18 Rate Researching Tool Version 2") | |
println("By XGN from HHS 2022") | |
println("Preparing Selenium Chrome Driver...") | |
val option=ChromeOptions() | |
option.setPageLoadStrategy(PageLoadStrategy.EAGER) | |
WebDriverManager.chromedriver().setup() | |
driver= ChromeDriver(option) | |
println("Reading Character List from character.txt...") | |
val f= File("character.txt") | |
val chars=f.readLines() | |
println("Line Count: ${chars.size}") | |
login() | |
// solveChar(chars[0]) | |
for(i in ProgressBar.wrap(chars,"Characters")){ | |
if(i.trim()!=""){ | |
solveChar(i) | |
} | |
} | |
println("Printing Results to out.csv") | |
val fo=File("out.csv") | |
var pps="" | |
for(i in chars){ | |
val x=res[i]!! | |
pps+="$i,${x.first},${x.second},${x.third}\n" | |
} | |
fo.writeText(pps) | |
println("Done Finally!!!") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
zjs@yopmail.com | |
password123 | |
# THIS IS AN EXAMPLE FILE!!! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
<dependencies> | |
<dependency> | |
<groupId>org.jetbrains.kotlin</groupId> | |
<artifactId>kotlin-stdlib-jdk8</artifactId> | |
<version>1.5.10</version> | |
</dependency> | |
<dependency> | |
<groupId>org.seleniumhq.selenium</groupId> | |
<artifactId>selenium-java</artifactId> | |
<version>4.0.0</version> | |
</dependency> | |
<dependency> | |
<groupId>io.github.bonigarcia</groupId> | |
<artifactId>webdrivermanager</artifactId> | |
<version>5.0.3</version> | |
</dependency> | |
<dependency> | |
<groupId>me.tongfei</groupId> | |
<artifactId>progressbar</artifactId> | |
<version>0.9.2</version> | |
</dependency> | |
</dependencies> | |
... |
Update:
- Pixiv changed their login form class name and login requires Captcha now.
- Pixiv posed a stricter limit on automated script and API calling. 0 is returned if limit is hit.
In conclusion, this script does not work great now. An update will be carried out when I am free(Soon TM).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Several Notes: