def collectLinksLocal(self): driver = self.driver console.section("Uploading Local Known Images") pathlist = Path('./known').glob('**/*.jpg') for p in pathlist: str_p = str(p) driver.get("https://www.google.com/imghp") elems = driver.find_elements_by_xpath('//*[@id="qbi"]')[0] elems.click() time.sleep(1) elems = driver.find_element_by_xpath( '/html/body/div[1]/div[3]/div[3]/div/div[2]/form/div[1]/div/a') elems.click() time.sleep(1) console.subtask("Inserting Path") input_box = driver.find_element_by_xpath('//*[@id="qbfile"]') p_i = os.path.join(os.getcwd(), str_p) input_box.send_keys(p_i) time.sleep(cfg.timeout() * 2) try: pred = driver.find_element_by_xpath( "/html/body/div[6]/div[3]/div[3]/div[1]/div[2]/div/div[2]/div[1]/div/div[2]/a" ) pred = pred.text except NoSuchElementException: console.subfailure('No Prediction given sry...') pred = None self.predictions.append(pred) link_name = driver.find_elements_by_xpath(".//h3[@class='r']/a") console.subtask("Collecting Links...(Page 1)") for link in link_name: href = link.get_attribute('href') if filterLink(href): console.subtask('Added {0}'.format(href)) self.links.append(href) for num in range(2, self.max_pages + 1): console.subtask("Switching to Page {0}".format(num)) try: page_n = driver.find_element_by_link_text(str(num)) page_n.click() time.sleep(cfg.timeout()) console.subtask( "Collecting Links...(Page {0})".format(num)) link_name = driver.find_elements_by_xpath( ".//h3[@class='r']/a") for link in link_name: href = link.get_attribute('href') if filterLink(href): console.subtask('Added {0}'.format(href)) self.links.append(href) except NoSuchElementException: console.subfailure('No more pages...') break
def collectLinks(self, img_url): console.task('New Image: {0}'.format(img_url.strip()[:90])) driver = self.driver driver.get("https://www.google.com/imghp") console.subtask('Inserting Image URL') console.task("Please agree to google's stuff in the browser") time.sleep(10) elems = driver.find_elements_by_xpath(self.PHOTO_XPATH)[0] elems.click() time.sleep(1) input = driver.find_elements_by_xpath('//*[@id="Ycyxxc"]')[0] input.clear() input.send_keys(img_url) input.send_keys(Keys.RETURN) console.subtask('Searching for Image...') time.sleep(cfg.timeout() * 2) pred_error = False try: pred = driver.find_element_by_xpath(self.PRED_XPATH) except NoSuchElementException: console.subfailure('No Prediction given sry...') pred = None pred_error = True except BrokenPipeError: #just try again... try: pred = driver.find_element_by_xpath(self.PRED_XPATH) except NoSuchElementException: console.subfailure( 'Broken pipe Error. This is not a Problem...moving on!') console.subfailure('No Prediction given sry...') pred = None pred_error = True if not pred_error: pred = pred.text self.predictions.append(pred) console.subtask("Collecting Links...(Page 1)") self.getLinks() for num in range(2, self.max_pages + 1): console.subtask("Switching to Page {0}".format(num)) try: page_n = driver.find_element_by_link_text(str(num)) page_n.click() time.sleep(cfg.timeout()) console.subtask("Collecting Links...(Page {0})".format(num)) self.getLinks() except NoSuchElementException: console.subfailure('No more pages...') break
def collectLinks(self, img_url): console.task('New Image: {0}'.format(img_url.strip()[:90])) driver = self.driver driver.get("https://www.google.com/imghp") console.subtask('Inserting Image URL') elems = driver.find_elements_by_xpath('//*[@id="qbi"]')[0] elems.click() time.sleep(1) input = driver.find_elements_by_xpath('//*[@id="qbui"]')[0] input.clear() input.send_keys(img_url) input.send_keys(Keys.RETURN) console.subtask('Searching for Image...') time.sleep(cfg.timeout()) try: pred = driver.find_element_by_xpath( "/html/body/div[5]/div[3]/div[3]/div[1]/div[2]/div/div[2]/div[1]/div/div[2]/a" ) pred = pred.text except NoSuchElementException: console.subfailure('No Prediction given sry...') pred = None self.predictions.append(pred) link_name = driver.find_elements_by_xpath(".//h3[@class='r']/a") console.subtask("Collecting Links...(Page 1)") for link in link_name: href = link.get_attribute('href') if filterLink(href): console.subtask('Added {0}'.format(href)) self.links.append(href) for num in range(2, self.max_pages + 1): console.subtask("Switching to Page {0}".format(num)) try: page_n = driver.find_element_by_link_text(str(num)) page_n.click() time.sleep(cfg.timeout()) console.subtask("Collecting Links...(Page {0})".format(num)) link_name = driver.find_elements_by_xpath( ".//h3[@class='r']/a") for link in link_name: href = link.get_attribute('href') if filterLink(href): console.subtask('Added {0}'.format(href)) self.links.append(href) except NoSuchElementException: console.subfailure('No more pages...') break
def collectLinks(self, img_url): l_unreal = [] console.task('New Image: {0}'.format(img_url.strip()[:90])) driver = self.driver driver.get("https://www.yandex.com/images/") console.subtask('Inserting Image URL') elems = driver.find_elements_by_xpath( '/html/body/div[1]/div/div[1]/div[2]/form/div[1]/span/span/table/tbody/tr/td[2]/div/button' )[0] elems.click() input = driver.find_elements_by_xpath( '/html/body/div[3]/div/div[1]/div/form[2]/span/span/input')[0] input.clear() input.send_keys(img_url) input.send_keys(Keys.RETURN) console.subtask('Searching for Image...') time.sleep(cfg.timeout()) link_name = driver.find_elements_by_xpath( '/html/body/div[6]/div[1]/div[1]/div[3]/ul/li/div/a[2]') console.subtask("Collecting Links...") for link in link_name: href = link.get_attribute('href') l_unreal.append(href) console.subtask("Getting real links from Yandex ShortURLs") l_real = [] for l_u in l_unreal: driver.get(l_u) if (filterLink(driver.current_url)): l_real.append(driver.current_url) console.subtask('Added verified {0}'.format( driver.current_url.strip()[:90])) self.links = l_real
def collectAges(self, img_url): if not self.driver: self.driver = cfg.getWebDriver() console.task('New Image: {0}'.format(img_url.strip()[:90])) driver = self.driver driver.get("http://www.pictriev.com/?lang=en") console.subtask('Inserting Image URL') input = driver.find_elements_by_xpath('//*[@id="urltext"]')[0] input.clear() input.send_keys(img_url) btn = driver.find_elements_by_xpath('//*[@id="submit-url"]')[0] btn.click() console.subtask('Searching for Image...') time.sleep(cfg.timeout() * 3) try: age = driver.find_elements_by_css_selector( '#age-gauge > svg:nth-child(1) > text:nth-child(6) > tspan:nth-child(1)' ) except: age = driver.find_elements_by_css_selector( '#age-gauge > svg:nth-child(1) > text:nth-child(6) > tspan:nth-child(1)' ) if len(age) == 1: age = age[0].text else: age = 0 self.ages.append(int(age))
def collectLinksLocal(self): l_unreal = [] console.task('Uploading Local Images') driver = self.driver driver.get("https://www.yandex.com/images/") pa_g = Path('./known') pathlist = [] for ext in [ '.jpg', '.JPG', '.png', '.PNG', '.jpeg', '.JPEG', '.bmp', '.BMP' ]: tmp_pl = pa_g.glob('**/*{}'.format(ext)) for t in tmp_pl: pathlist.append(t) for p in pathlist: str_p = str(p) console.subtask('Inserting Image URL') time.sleep(5) elems = driver.find_elements_by_xpath( '/html/body/div[1]/div[2]/div[1]/div[1]/div[1]/div/div/div/div[1]/div[2]/form/div[1]/span/span[2]' )[0] elems.click() input = driver.find_elements_by_xpath( '/html/body/div[1]/div[2]/div[1]/div[1]/div[1]/div/div/div/div[4]/div/div[1]/div/form[1]/input' )[0] input.clear() p_i = os.path.join(os.getcwd(), str_p) input.send_keys(p_i) console.subtask('Searching for Image...') time.sleep(cfg.timeout()) link_name = driver.find_elements_by_xpath( '/html/body/div[6]/div[1]/div[1]/div[3]/ul/li/div/a[2]') console.subtask("Collecting Links...") for link in link_name: href = link.get_attribute('href') l_unreal.append(href) console.subtask("Getting real links from Yandex ShortURLs") l_real = [] for l_u in l_unreal: driver.get(l_u) if (filterLink(driver.current_url)): l_real.append(driver.current_url) console.subtask('Added verified {0}'.format( driver.current_url.strip()[:90])) for l in l_real: self.links.append(l)
def collectLinksLocal(self): driver = self.driver console.section("Uploading Local Known Images") pa_g = Path('./known') pathlist = [] for ext in [ '.jpg', '.JPG', '.png', '.PNG', '.jpeg', '.JPEG', '.bmp', '.BMP' ]: tmp_pl = pa_g.glob('**/*{}'.format(ext)) for t in tmp_pl: pathlist.append(t) for p in pathlist: str_p = str(p) driver.get("https://www.google.com/imghp") elems = driver.find_elements_by_xpath(self.PHOTO_XPATH)[0] elems.click() time.sleep(1) elems = driver.find_element_by_xpath(self.PHOTO_UPLOAD_XPATH) elems.click() time.sleep(1) console.subtask("Inserting Path") input_box = driver.find_element_by_xpath('//*[@id="qbfile"]') p_i = os.path.join(os.getcwd(), str_p) input_box.send_keys(p_i) time.sleep(cfg.timeout() * 2) pred_error = False try: pred = driver.find_element_by_xpath(self.PRED_XPATH) except NoSuchElementException: console.subfailure('No Prediction given sry...') pred = None pred_error = True except BrokenPipeError: #just try again... try: pred = driver.find_element_by_xpath(self.PRED_XPATH) except NoSuchElementException: console.subfailure( 'Broken pipe Error. This is not a Problem...moving on!' ) console.subfailure('No Prediction given sry...') pred = None pred_error = True if not pred_error: pred = pred.text self.predictions.append(pred) console.subtask("Collecting Links...(Page 1)") self.getLinks() for num in range(2, self.max_pages + 1): console.subtask("Switching to Page {0}".format(num)) try: page_n = driver.find_element_by_link_text(str(num)) page_n.click() time.sleep(cfg.timeout()) console.subtask( "Collecting Links...(Page {0})".format(num)) self.getLinks() except NoSuchElementException: console.subfailure('No more pages...') break
def collectLinks(self, img_url): console.task('New Image: {0}'.format(img_url.strip()[:90])) driver = self.driver driver.get("https://www.google.com/imghp") console.subtask('Inserting Image URL') elems = driver.find_elements_by_xpath(self.PHOTO_XPATH)[0] elems.click() time.sleep(1) input = driver.find_elements_by_xpath('//*[@id="qbui"]')[0] input.clear() input.send_keys(img_url) input.send_keys(Keys.RETURN) console.subtask('Searching for Image...') time.sleep(cfg.timeout() * 2) pred_error = False try: pred = driver.find_element_by_xpath(self.PRED_XPATH) except NoSuchElementException: console.subfailure('No Prediction given sry...') pred = None pred_error = True except BrokenPipeError: #just try again... try: pred = driver.find_element_by_xpath(self.PRED_XPATH) except NoSuchElementException: console.subfailure( 'Broken pipe Error. This is not a Problem...moving on!') console.subfailure('No Prediction given sry...') pred = None pred_error = True if not pred_error: pred = pred.text self.predictions.append(pred) try: link_name = driver.find_elements_by_xpath("//*[@class='iUh30']") #link_name=driver.find_elements_by_xpath(".//h3[@class='r']/a") except BrokenPipeError: link_name = driver.find_elements_by_xpath("//*[@class='iUh30']") #link_name=driver.find_elements_by_xpath(".//h3[@class='r']/a") console.subtask("Collecting Links...(Page 1)") if len(link_name) <= 0: console.subfailure('No Links found') else: for link in link_name: #href = link.get_attribute('href') if link != None: href = link.text if filterLink(href): console.subtask('Added {0}'.format(href)) self.links.append(href) for num in range(2, self.max_pages + 1): console.subtask("Switching to Page {0}".format(num)) try: page_n = driver.find_element_by_link_text(str(num)) page_n.click() time.sleep(cfg.timeout()) console.subtask("Collecting Links...(Page {0})".format(num)) try: link_name = driver.find_elements_by_xpath( "//*[@class='iUh30']") except BrokenPipeError: link_name = driver.find_elements_by_xpath( "//*[@class='iUh30']") for link in link_name: href = link.text if filterLink(href): console.subtask('Added {0}'.format(href)) self.links.append(href) except NoSuchElementException: console.subfailure('No more pages...') break
def collectLinksLocal(self): driver = self.driver console.section("Uploading Local Known Images") pa_g = Path('./known') pathlist = [] for ext in [ '.jpg', '.JPG', '.png', '.PNG', '.jpeg', '.JPEG', '.bmp', '.BMP' ]: tmp_pl = pa_g.glob('**/*{}'.format(ext)) for t in tmp_pl: pathlist.append(t) for p in pathlist: str_p = str(p) driver.get("https://www.google.com/imghp") elems = driver.find_elements_by_xpath( '/html/body/div/div[3]/div[3]/form/div[2]/div/div[1]/div/div[2]/div' )[0] elems.click() time.sleep(1) elems = driver.find_element_by_xpath( '/html/body/div[1]/div[3]/div[3]/div/div[2]/form/div[1]/div/a') elems.click() time.sleep(1) console.subtask("Inserting Path") input_box = driver.find_element_by_xpath('//*[@id="qbfile"]') p_i = os.path.join(os.getcwd(), str_p) input_box.send_keys(p_i) time.sleep(cfg.timeout() * 2) pred_error = False try: pred = driver.find_element_by_xpath( "/html/body/div[5]/div[3]/div[3]/div[1]/div[2]/div/div[2]/div[1]/div/div[2]/a" ) except NoSuchElementException: console.subfailure('No Prediction given sry...') pred = None pred_error = True except BrokenPipeError: #just try again... try: pred = driver.find_element_by_xpath( "/html/body/div[5]/div[3]/div[3]/div[1]/div[2]/div/div[2]/div[1]/div/div[2]/a" ) except NoSuchElementException: console.subfailure( 'Broken pipe Error. This is not a Problem...moving on!' ) console.subfailure('No Prediction given sry...') pred = None pred_error = True if not pred_error: pred = pred.text self.predictions.append(pred) try: link_name = driver.find_elements_by_xpath( "//*[@class='iUh30']") except BrokenPipeError: link_name = driver.find_elements_by_xpath( "//*[@class='iUh30']") console.subtask("Collecting Links...(Page 1)") if len(link_name) <= 0: console.subfailure('No Links found') else: for link in link_name: if link != None: href = link.text if filterLink(href): console.subtask('Added {0}'.format(href)) self.links.append(href) for num in range(2, self.max_pages + 1): console.subtask("Switching to Page {0}".format(num)) try: page_n = driver.find_element_by_link_text(str(num)) page_n.click() time.sleep(cfg.timeout()) console.subtask( "Collecting Links...(Page {0})".format(num)) try: link_name = driver.find_elements_by_xpath( "//*[@class='iUh30']") except BrokenPipeError: link_name = driver.find_elements_by_xpath( "//*[@class='iUh30']") for link in link_name: href = link.text if filterLink(href): console.subtask('Added {0}'.format(href)) self.links.append(href) except NoSuchElementException: console.subfailure('No more pages...') break