Selenium-rc:有没有办法发送请求缓冲区

发布于 2024-08-17 01:37:16 字数 499 浏览 2 评论 0原文

假设我有一个链接列表,想要随机单击一个链接:

<div id="divA">
   <a> first link </a>
   <a> second link </a>
   ...
</div>

这不是最聪明的方法(如果您有更好的解决方案,请告诉我),但我目前所做的(大致)是:

l = []
for i in range(numOfLinks):
    xpath = '//div[@id="divA"]/a[%d]'%i
    txt = sel.getText(xpath)
    l.append(xpath, txt)

xpath,linkName = random.choice(l)
sel.click(xpath)

主要问题该解决方案的主要特点是它向 selenium 发送许多请求。我的问题是:有没有办法将所有这些请求保存在缓冲区中并立即发送?

Lets say I have a list of links and want to click a link at random:

<div id="divA">
   <a> first link </a>
   <a> second link </a>
   ...
</div>

It isn't the smartest of ways (and if you have a better solution please tell me) but what I currently do is (roughly):

l = []
for i in range(numOfLinks):
    xpath = '//div[@id="divA"]/a[%d]'%i
    txt = sel.getText(xpath)
    l.append(xpath, txt)

xpath,linkName = random.choice(l)
sel.click(xpath)

The main problem of this solution is that it sends many requests to selenium. My question is: is there a way of saving all these requests in a buffer and sending them at once?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

顾挽 2024-08-24 01:37:16

你用文字做任何事吗?

numOfLinks = sel.get_xpath_count('//div[@id="divA"]/a')
random.randrange(1,numOfLinks)
sel.click('//div[@id="divA"]/a[%d]'%random.randrange(1,numOfLinks))

上面的代码将始终单击随机链接,而不必每次都获取链接的文本。

are you using the text for anything?

numOfLinks = sel.get_xpath_count('//div[@id="divA"]/a')
random.randrange(1,numOfLinks)
sel.click('//div[@id="divA"]/a[%d]'%random.randrange(1,numOfLinks))

The code above will always click on a random link without having to get the text of the link each time.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文