小编duh*_*ime的帖子

Python 中的 Selenium:选择具有给定链接文本的第二个元素

我试图单击包含链接文本“查看此文本中的所有命中”的网页上的所有链接。下面是网页上的一些 html 的样子:

<a href="/searchCom.do?offset=24981670&entry=4&entries=112&area=Poetry&forward=textsCom&queryId=../session/1380145118_2069"><b>View all hits in this text</b>
<br>
</a>

[...]

<a href="/searchCom.do?offset=25280103&entry=5&entries=112&area=Poetry&forward=textsCom&queryId=../session/1380145118_2069"><b>View all hits in this text</b>
<br>
</a>
Run Code Online (Sandbox Code Playgroud)

如果页面上只有一个这样的链接,我知道我可以使用以下内容单击它:

driver.find_element_by_link_text('View all hits in this text').click()
Run Code Online (Sandbox Code Playgroud)

不幸的是,这种方法只能识别并点击网页上带有链接文本“查看此文本中的所有命中”的第一个链接。因此,我想问:有没有一种方法可以用来单击此页面上带有链接文本“查看此文本中的所有命中”的第二个(或第 n 个)链接?我有一种感觉,我可能需要使用 xpath,但我还没有完全弄清楚应该如何在我的脚本中实现 xpath。如果其他人可以借出任何建议,我将不胜感激。

python selenium xpath webdriver

5
推荐指数
1
解决办法
4805
查看次数

Python Tkinter:AttributeError:Checkbutton 实例没有属性“get”

我是 Tkinter 的新手。我正在尝试创建一个具有两个旋转框和两个复选框的 GUI,当用户单击特定按钮(“开始”)时,将打印其值。到目前为止,这是我的代码:

from Tkinter import *
from tkFileDialog import askopenfilename
from PIL import Image

#create TK frame
root = Tk()
#identify the dimensions of the TK frame
root.geometry("360x150")
#title the TK frame
root.title("Literature Online API")

#create a function that will return the filepath for a file provided by the user
def selectfile():
    user_defined_filepath['filename'] = askopenfilename(filetypes=[("Text","*.txt")]) # user_defined_filepath['filename'] may now be accessed in the global scope.

#create a function that will allow the "start" button to begin further processes …
Run Code Online (Sandbox Code Playgroud)

python checkbox user-interface tkinter

5
推荐指数
1
解决办法
1万
查看次数

Pika python异步发布者:如何通过控制台从用户发送数据?

我正在使用标准的异步发布者示例.我注意到发布者将永远在循环中继续发布相同的消息.所以我评论了来自publish_message的schedule_next_message调用来停止该循环.但我真正想要的只是当用户给它一个"message_body"和"Key"时,publissher才能开始发布

基本上是发布者发布用户输入.

我无法找到如何使发布者实时接收用户输入的任何示例或提示.我是raabitmq,pika,python等的新手

这是我正在谈论的代码片段: -

def publish_message(self):
    """If the class is not stopping, publish a message to RabbitMQ,
    appending a list of deliveries with the message number that was sent.
    This list will be used to check for delivery confirmations in the
    on_delivery_confirmations method.

    Once the message has been sent, schedule another message to be sent.
    The main reason I put scheduling in was just so you can get a good idea
    of how the process is flowing by slowing …
Run Code Online (Sandbox Code Playgroud)

python asynchronous pika

5
推荐指数
1
解决办法
2864
查看次数

Python:Goslate翻译请求返回"503:服务不可用"

几个月前,我使用Python的goslate软件包将一堆法语文本翻译成英文.但是,当我今天早上尝试这样做时,该服务返回了一个错误:

import goslate
gs = goslate.Goslate()
print gs.translate('hello world', 'de')

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\Python27\lib\site-packages\goslate.py", line 389, in translate
    return _unwrapper_single_element(self._translate_single_text(text, target_language, source_language))
  File "c:\Python27\lib\site-packages\goslate.py", line 317, in _translate_single_text
    results = list(self._execute(make_task(i) for i in split_text(text)))
  File "c:\Python27\lib\site-packages\goslate.py", line 200, in _execute
    yield each()
  File "c:\Python27\lib\site-packages\goslate.py", line 315, in <lambda>
    return lambda: self._basic_translate(text, target_language, source_lauguage)[0]
  File "c:\Python27\lib\site-packages\goslate.py", line 241, in _basic_translate
    response_content = self._open_url(url)
  File "c:\Python27\lib\site-packages\goslate.py", line 178, in _open_url …
Run Code Online (Sandbox Code Playgroud)

python translation nlp machine-translation

5
推荐指数
1
解决办法
3726
查看次数

ggplot2:为facet_grid/facet_wrap绘图的每一行指定唯一的宽度

我想为R中的一列,facet-wrapped图的每一行分配一个自定义宽度.(我知道这完全是非标准的.)

随着grid.arrange我一个独特的高分配的各行的小包裹的像下面的代码片段剧情:

group1 <- seq(1, 10, 2)
group2 <-  seq(1, 20, 3)
x = c(group1, group2)
mydf <- data.frame (X =x , Y = rnorm (length (x),5,1), 
                    groups = c(rep(1, length (group1)), rep(2, length(group2))))

plot1 <- ggplot(mydf, aes(X, Y)) + geom_point()
plot2 <- ggplot(mydf, aes(X, Y)) + geom_point()

grid.arrange(plot1, plot2, heights=c(1,2))
Run Code Online (Sandbox Code Playgroud)

上面的代码为图的每一行提供了一个独特的高度:

在此输入图像描述

我想知道是否可以为绘图的每一行指定一个唯一的宽度,而不是为每一行指定一个唯一的高度.是否可以使用任何ggplot2扩展名?

plot visualization r ggplot2 r-grid

5
推荐指数
1
解决办法
890
查看次数

为什么Atob和Btoa不可逆

我正在尝试找到一种简单的方法来记录和暂时混淆我在Markdown中编写的“测验”问题的答案。(在演示过程中,我会告诉学生测验答案,因此,我不需要任何类型的安全加密。)

我以为我可以用atob('message I want to obfuscate')然后告诉学生,他们可以btoa()在开发人员工具面板中使用以逆转该过程。但是,以下内容不会返回“ one”:

btoa( atob('one') )
Run Code Online (Sandbox Code Playgroud)

有谁知道为什么这个不回来'one'?JavaScript中是否还有其他方法可以使您轻松地对消息进行加密和解密?(我与绝对的初学者一起工作,这些初学者可能会对功能感到困惑,并且对将库添加到页面会感到非常困惑)。

javascript encoding

5
推荐指数
1
解决办法
270
查看次数

量化 numpy 向量的快速方法

我有大量的 numpy 向量,每个形状 (3,) 具有 8 位整数值:

vec = np.random.randint(2**8, size=3)
Run Code Online (Sandbox Code Playgroud)

我想通过一些已知的缩减因子将这些向量量化到更小的空间。我知道我可以通过定义另一个带有定义信息丢失量的值的向量,除以vec该向量,然后将结果值转换回整数,在一系列操作中解决这个问题:

>>> vec = np.random.randint(2**8, size=3)
>>> denominator = np.full(3, 8)
>>> divided = vec / denominator
>>> ints = divided.astype(int)
>>> ints *= denominator
>>>
>>> vec
array([205, 182,  99])
>>> ints
array([200, 176,  96])
Run Code Online (Sandbox Code Playgroud)

有没有更快的方法来量化这些 numpy 向量?对于其他人可以就这个问题分享的任何想法,我将不胜感激。

python numpy vector

5
推荐指数
1
解决办法
5343
查看次数

react.js | 如何摆脱Codesandbox中的跨域错误

简而言之:执行代码时,我应该得到的典型错误是:“ TypeError:无法读取未定义的属性'setState'”,相反,我收到了一个非常奇怪的跨域错误。

这是错误的屏幕截图:http : //prntscr.com/iwipnb 在此处输入图片说明

错误引发了跨域错误。React不能访问开发中的实际错误对象。有关更多信息,请参见https://reactjs.org/docs/cross-origin-errors.html

这是我的代码:https : //codesandbox.io/s/4885l37xrw

如何避免FIREFOX中Codesandbox 的跨域错误?

EDIT1:我知道什么是代码错误(bind(this))。我正在寻找跨域错误 firefox问题。谢谢

amazon-s3 reactjs codesandbox

5
推荐指数
1
解决办法
5909
查看次数

Redis:原子获取和条件设置

我想GET在 Redis 中执行一个原子操作,如果返回的值等于某个预期值,我想执行一个SET,但我想将所有这些链接在一起作为一个原子操作。(我正在尝试设置一个标志,指示是否有任何进程正在将数据写入磁盘,因为可能只允许一个进程这样做。)

是否有可能用 Redis 来完成?

我看过有关MULTI操作的文档,但我还没有看过条件操作和MULTI操作。其他人可以提供的任何建议将不胜感激!

lua conditional atomic redis

5
推荐指数
1
解决办法
5965
查看次数

Python:只保留最后 n 个插入键的字典

我打算从磁盘读取数百万个小文件。为了最小化 i/o,我计划使用一个将文件路径映射到其内容的字典。我只希望字典保留插入其中的最后 n 个键(因此字典将充当缓存)。

Python 中是否有数据结构已经实现了这种行为?我想在重新发明轮子之前检查一下。

python dictionary data-structures

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