fork download
  1. import time
  2. import base64
  3. from PIL import Image
  4. from io import BytesIO
  5. from urllib.request import urlretrieve
  6. from selenium import webdriver
  7. from selenium.webdriver.support.ui import WebDriverWait
  8. from selenium.webdriver.support import expected_conditions as EC
  9. from selenium.webdriver.common.by import By
  10. from selenium.webdriver.common.keys import Keys
  11. from selenium.webdriver.common.action_chains import ActionChains
  12.  
  13.  
  14. driver = webdriver.Firefox()
  15. driver.get("https://m...content-available-to-author-only...o.jp/viewer/1007477") # Open chapter
  16.  
  17. settings = WebDriverWait(driver, 10).until(EC.presence_of_element_located(
  18. (By.XPATH, "//div[starts-with(@class, 'Navigation-module_settingsContainer_')]"))) # Find settings button with wait
  19. settings.click() # Open settings
  20. driver.find_elements_by_xpath("//div[starts-with(@class, 'Modal-module_quarity_')]")[2].click() # Set image quality
  21. settings.click() # Open settings again
  22. driver.execute_script('document.querySelector("input#mode-horizontal").removeAttribute("disabled")') # Endble horizontal if it disabled
  23. driver.execute_script('document.querySelector("input#mode-horizontal").click()') # Turn into horizontal mode
  24.  
  25.  
  26.  
  27. title = WebDriverWait(driver, 10).until(EC.presence_of_element_located(
  28. (By.XPATH, '/html/body/div/div[2]/div[2]/div[3]/div[1]/div[2]/a/h1'))).text # Wait for page load after refresh
  29. chapter = driver.find_element_by_xpath('/html/body/div/div[2]/div[2]/div[3]/div[1]/div[2]/div/p').text[1:]
  30. time.sleep(2)
  31.  
  32. img = driver.find_element_by_class_name('zao-image')
  33.  
  34.  
  35.  
  36. b64 = driver.execute_script('''function getBase64Image(img)
  37. {
  38. var canvas = document.createElement("canvas");
  39. canvas.width = img.width;
  40. canvas.height = img.height;
  41. var ctx = canvas.getContext("2d");
  42. ctx.drawImage(img, 0, 0);
  43. var dataURL = canvas.toDataURL("image/png");
  44. return dataURL.replace(/^data:image\/(png|jpg);base64,/, "");
  45. }
  46. return getBase64Image(arguments[0])
  47. ''',
  48. img)
  49. image_data = base64.b64decode(b64)
  50.  
  51. with open('pic.png', 'wb') as f:
  52. f.write(image_data)
  53.  
  54.  
Runtime error #stdin #stdout #stderr 0.03s 64016KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "prog.py", line 3, in <module>
    from PIL import Image
ImportError: No module named PIL