-
Notifications
You must be signed in to change notification settings - Fork 2
/
scrape.py
29 lines (26 loc) · 987 Bytes
/
scrape.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import time
import os
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.keys import Keys
def download_book(url, name):
chromedriver = '/home/rajdeep1008/Desktop/chromedriver'
os.environ["webdriver.chrome.driver"] = chromedriver
driver = webdriver.Chrome(chromedriver)
driver.get(url)
link = driver.find_element_by_link_text(name)
actionChains = ActionChains(driver)
actionChains.context_click(link)
actionChains.send_keys(Keys.ARROW_DOWN)
actionChains.send_keys(Keys.ARROW_DOWN)
actionChains.send_keys(Keys.ARROW_DOWN)
actionChains.send_keys(Keys.ARROW_DOWN)
actionChains.send_keys(Keys.RETURN)
actionChains.perform()
while True:
if not os.path.isfile('/home/rajdeep1008/Downloads/' + name + '.pdf'):
time.sleep(5)
else:
break
driver.quit()
# download_book('http://it-ebooks.info/book/6719/', 'Android Studio Game Development')