小编Eva*_*ler的帖子

Google Cloud Vision API 中的 API 密钥位于何处?

想要使用 Google 的 Cloud Vision API 进行 OCR。使用这里的python 示例代码,我们有:

def detect_text(path):
"""Detects text in the file."""
client = vision.ImageAnnotatorClient()

with io.open(path, 'rb') as image_file:
    content = image_file.read()

image = types.Image(content=content)

response = client.text_detection(image=image)
texts = response.text_annotations
print('Texts:')

for text in texts:
    print('\n"{}"'.format(text.description))

    vertices = (['({},{})'.format(vertex.x, vertex.y)
                for vertex in text.bounding_poly.vertices])

    print('bounds: {}'.format(','.join(vertices)))
Run Code Online (Sandbox Code Playgroud)

我应该把 API 密钥放在哪里?没有它我(显然)无法进行身份验证。

python ocr google-cloud-vision

6
推荐指数
1
解决办法
2117
查看次数

React onMouseEnter 和 onMouseLeave 的行为不一致

我有一个 div,如果光标悬停在其上,则应该显示“HOVERING”,否则显示“NOT HOVERING”。由于某种原因,如果我慢慢地将每个 div 悬停在页面上,它的行为就会符合预期;但是,如果我在屏幕上快速移动光标,某些 div 就会被切换。意思是,当我的光标移动到 div 上时,它们将显示“NOT HOVERING”,当我的光标不在 div 上时,它们将显示“HOVERING”。

Chrome 和 Safari 中都会出现此错误。

沙盒:

https://codesandbox.io/s/ged-butterfly-r2g6x?file=/src/Geo.js

将光标快速移动到方框上以查看问题。

javascript reactjs

3
推荐指数
1
解决办法
9970
查看次数

jQuery滚动事件每个滚动一次

我有一些jQuery代码来检查我是否滚动到窗口的底部.

$(window).scroll(function(){
    if($(window).scrollTop() + $(window).height() == $(document).height()) {
        appendToGrid();
    }
})
Run Code Online (Sandbox Code Playgroud)

我的appendToGrid()函数将用户滚动到页面顶部并添加内容.问题是,我需要每个滚动调用一次这个函数.就像我现在一样,它每次滚动被调用多次.

如果我改成它

$(window).one('scroll',function() {
    if($(window).scrollTop() + $(window).height() == $(document).height()) {
        appendToGrid();
    }
});
Run Code Online (Sandbox Code Playgroud)

它只会触发一次,但我需要它每次滚动一次,所以用户可以滚动到底部并继续发送回页面顶部.

我也尝试过以下但它仍然会多次发射.

var fired = false;
$(window).scroll(function(){
    if($(window).scrollTop() + $(window).height() == $(document).height() && !fired) {
        fired = true;
        appendToGrid();
        fired = false;
    }
})
Run Code Online (Sandbox Code Playgroud)

javascript jquery scroll

2
推荐指数
2
解决办法
2089
查看次数

ImportXML 未生成正确的值

我正在按照以下教程将股票期权数据导入 Google 工作表。

https://www.youtube.com/watch?v=Be7z9YeeVY0&ab_channel=daneshj

以下公式将把雅虎财经的数据导入到工作表中:

=iferror(TRANSPOSE(IMPORTXML(CONCATENATE("https://finance.yahoo.com/quote/",A2,"?p=",A2),"//tr")),"You have to add a contract name in column A")
Run Code Online (Sandbox Code Playgroud)

乍一看,一切看起来都很好,因为它似乎是从网页上拉回数据;然而,所有的值都是不正确的

本示例中从中提取数据的 URL 如下。请注意,数据经常变化。

https://finance.yahoo.com/quote/NKLA220121C00002500?p=NKLA220121C00002500

这些数字不仅在这个特定示例中是错误的,而且每次都是错误的,并且误差范围足够大,我不认为这是由于 IMPORTXML 缓存页面造成的。我已经搜索了网页的 HTML 源代码,但在任何地方都找不到 IMPORTXML 中的值。

在此输入图像描述

在此输入图像描述

google-sheets web-scraping google-apps-script yahoo-finance google-sheets-formula

0
推荐指数
1
解决办法
1043
查看次数