Instantly share code, notes, and snippets.

What would you like to do?
# 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 import WebDriverWait
from import expected_conditions as EC
from import By
from import Options
from fake_useragent import UserAgent
import re
import sys
options = Options()
ua = UserAgent()
a = ua.random
user_agent = ua.random
driver = webdriver.Chrome(chrome_options=options)
for x in range(1,21):
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"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)
print "Unexpected error:", sys.exc_info()[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment