Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from selenium import webdriver
- import requests, sys, webbrowser, bs4, string, time, os
- driver = webdriver.Chrome(executable_path=r'C:\Users\mbarn\Desktop\PythonScripts\chromedriver.exe')
- driver.get('https://gelbooru.com/index.php?page=post&s=view&id=4880645&tags=23_(real_xxiii)')
- url = 'https://gelbooru.com/index.php?page=post&s=view&id=4880645&tags=23_(real_xxiii)'
- os.makedirs('C:/Users/mbarn/Desktop/23', exist_ok = True)
- while not url.endswith('#'):
- #Download the page
- print('Downloading page %s. . .', (url))
- res = requests.get(url)
- res.raise_for_status()
- if res.status_code == 200:
- print('Success!')
- elif res.status_code == 404:
- printf('Not found')
- soup = bs4.BeautifulSoup(res.text)
- imageElem = driver.find_element_by_xpath("//meta[@property='og:image']")
- if imageElem == []:
- print('Could not find image')
- else:
- print(str(imageElem[0]))
- imageUrl = imageElem[0].get('content')
- print('Downloading image %s. . . ', (imageUrl))
- res = requests.get(imageUrl)
- res.raise_for_status()
- if res.status_code == 200:
- print('Successfl download')
- elif res.status_code == 404:
- printf('Unsuccessful download')
- #Save image to folder 23.
- imageFile = open(os.path.join("C:/Users/mbarn/Desktop/23", os.path.basename(imageUrl)),'wb' )
- for chunk in res.iter_content(5000000):
- imageFile.write(chunk)
- imageFile.close()
- #Click the next button.
- nextButton = driver.find_elements_by_link_text('Next')[0]
- nextButton.click()
- nextUrl = soup.select("img#image")
- imageUrl = nextUrl[0].get('src')
- print('All images downloaded.')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement