我有一个应用程序,它基本上是存储在我本地驱动器上的图像数据库.有时我需要找到更高分辨率的版本或图像的网络源,而谷歌的反向图像搜索是理想的选择.
不幸的是,谷歌没有它的API,所以我不得不想办法手动完成它.现在我正在使用Selenium,但这显然有很多开销.我想要一个简单的解决方案,使用urllib2或类似的东西 - 发送POST请求,获取搜索URL,然后我可以传递该URL以webbrowser.open(url)在我已打开的系统浏览器中加载它.
这就是我现在正在使用的:
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 …Run Code Online (Sandbox Code Playgroud) 我有一个线图和 2 条 hlines,都使用不同的颜色,我正在用 hline 的颜色填充主线与 hlines 交叉的区域。除此之外,我想对这些区域的主线使用相同的颜色。简而言之,当前输出:

以及我目前使用的相关代码:
lower, upper = 20, 80
self.indicatorPlot.axhline(lower, color="red")
self.indicatorPlot.axhline(upper, color="green")
self.indicatorPlot.plot(self.chartTimes, self.indicatorData, color="blue")
self.indicatorPlot.fill_between(self.chartTimes, self.indicatorData, lower, where=(self.indicatorData <= lower), facecolor="red", interpolate=True)
self.indicatorPlot.fill_between(self.chartTimes, self.indicatorData, upper, where=(self.indicatorData >= upper), facecolor="green", interpolate=True)
Run Code Online (Sandbox Code Playgroud)