Advertisement
Guest User

Untitled

a guest
Jun 21st, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.66 KB | None | 0 0
  1. #!  python3
  2. from selenium import webdriver
  3. from selenium.webdriver.common.by import By
  4. from selenium.webdriver.support.ui import WebDriverWait
  5. from selenium.webdriver.support import expected_conditions as EC
  6. import requests, os, bs4, time, sys, pyautogui
  7.  
  8. def newManga(nName):
  9.     #   Open Chrome and navigate to latest manga chapter for nName
  10.     browser = webdriver.Chrome()
  11.     browser.get(('http://mangakakalot.com/'))
  12.     search = browser.find_element_by_id('search_story')
  13.     search.send_keys(nName)
  14.     pyautogui.typewrite(['enter'])
  15.     latestChap = browser.find_element_by_class_name('item-chapter')
  16.     latestChap.click()
  17.     #   Download the Page
  18.     url = browser.current_url
  19.     print('Downloading page %s...' % url)
  20.     res = requests.get(url)
  21.     res.raise_for_status()
  22.     soup = bs4.BeautifulSoup(res.text, 'lxml')
  23.     #   Find the url of the manga image.
  24.     mangaElem = soup.select('#vungdoc img')
  25.     if mangaElem == []:
  26.         print('Could not find manga image.')
  27.  
  28.     else:
  29.         i = 0
  30.         for i in mangaElem:
  31.             mangaUrl = mangaElem[int(i)].get('src')
  32.             #   Download the image.
  33.             print('Download image %s...' % (mangaUrl))
  34.             res = requests.get(mangaUrl)
  35.         requestses.raise_for_status()
  36.         #   Save the image to ./manga
  37.         imageFile = open(os.path.join('manga', os.path.basename(mangaUrl)), 'wb')
  38.         for chunk in res.iter_content(1000000):
  39.             imageFile.write(chunk)
  40.         imageFile.close()
  41.         i += 1
  42.  
  43.  
  44.  
  45.  
  46. #   Ask for new manga
  47. print('Do you have a new manga to add? Y or N')
  48. confirm = input()
  49.  
  50. #   If Y or y, input manga name as nName, cale newManga(nName)
  51. if confirm == 'Y' or 'y':
  52.     print('Enter manga name to search: ')
  53.     nName = input()
  54.     newManga(nName)
  55. else:
  56.     print('No new manga, closing...')
  57.     exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement