Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
nanatsu
# The standard library modules
import os
import sys
# The wget module
import wget
import requests
import shutil
# The BeautifulSoup module
from bs4 import BeautifulSoup
# The selenium module
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from fake_useragent import UserAgent
import re
import sys
options = Options()
options.add_argument("window-size=1400,600")
ua = UserAgent()
a = ua.random
user_agent = ua.random
print(user_agent)
options.add_argument('user-agent='+user_agent)
driver = webdriver.Chrome(chrome_options=options)
for x in range(1,21):
try:
driver.get('https://manga-mx.com/manga/nanatsu-no-taizai/2433/p'+str(x))
WebDriverWait(driver, 5).until(EC.visibility_of_element_located((By.ID, "m_img")))
#waits till the element with the specific id appears
src = driver.page_source # gets the html source of the page
#print src
parser = BeautifulSoup(src,"lxml") # initialize the parser and parse the source "src"
list_of_attributes = {"id" : "m_img"} # A list of attributes that you want to check in a tag
tag = parser.findAll('img',attrs=list_of_attributes) # Get the video tag from the source
n = 0 # Specify the index of video element in the web page
url = tag[n]['src'] # get the src attribute of the video
print url
#wget.download("http:"+url,out="/home/diegocampos/"+str(x)+".jpg") # download the video
#if False:
if "http" not in url :
url = "http:"+url
r = requests.get(url,
stream=True, headers={'User-agent': user_agent})
if r.status_code == 200:
with open("nanatsu/"+str(x)+".jpg", 'wb') as f:
r.raw.decode_content = True
shutil.copyfileobj(r.raw, f)
except:
print "Unexpected error:", sys.exc_info()[0]
driver.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment