-
Notifications
You must be signed in to change notification settings - Fork 10
/
test_2.py
27 lines (22 loc) · 827 Bytes
/
test_2.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
gotUrl = QtCore.pyqtSignal(str)
filePath = "/mnt/Images/test.png"
browser = webdriver.Firefox()
browser.get('http://www.google.hr/imghp')
# Click "Search by image" icon
elem = browser.find_element_by_class_name('gsst_a')
elem.click()
# Switch from "Paste image URL" to "Upload an image"
browser.execute_script("google.qb.ti(true);return false")
# Set the path of the local file and submit
elem = browser.find_element_by_id("qbfile")
elem.send_keys(filePath)
# Get the resulting URL and make sure it's displayed in English
browser.get(browser.current_url+"&hl=en")
try:
# If there are multiple image sizes, we want the URL for the "All sizes" page
elem = browser.find_element_by_link_text("All sizes")
elem.click()
gotUrl.emit(browser.current_url)
except:
gotUrl.emit(browser.current_url)
browser.quit()