PYTHON + SELENIUM(CHROME):如何从当前网址中提取特定文本并使用提取的文本转到另一个文本?

问题描述 投票:1回答:1

我一直在使用iMacros,我有一个代码,我可以提取文本并使用它来创建我需要的特定网址。

它是这样的:

#I can extract the XPath text with this.
TAG XPATH="//*[@id="meio"]/div[2]/section/article[5]/h2/span/a" EXTRACT=TXT

#With this, I'm able to use that extracted text to go to another url. I think it's obvious to say, but I can place my word wherever I want with "{{!EXTRACT}}".
URL GOTO=https://www.spiritfanfiction.com/perfil/{{!EXTRACT}}

我可以在Python中使用这样的东西吗?

让我们说这是我目前的网址:

https://www.spiritfanfiction.com/perfil/depreciate

我需要提取“折旧”并使用它来转到此网址:

https://www.spiritfanfiction.com/mensagens/post?usuario=depreciate

Ps:在这种情况下,我无法直接从XPath中提取。它必须在当前的URL中。

谢谢。

python selenium google-chrome imacros
1个回答
0
投票

这是代码,它将为您提供所需的URL。

newURL = driver.current_url.split(".com")[0]+".com/mensagens/post?usuario=" +driver.current_url.split("/")[-1]
# navigate to newURL
driver.get(newURL)
© www.soinside.com 2019 - 2024. All rights reserved.