PYTHON + SELENIUM (CHROME):如何从当前 url 中提取特定文本并使用提取的文本转到另一个文本?
PYTHON + SELENIUM (CHROME): How can I extract a specific text from my current url and use the extracted text to go to another?
我使用 iMacros 已经很长时间了,我有一个代码可以提取文本并用它来创建我需要的特定 url。
事情是这样的:
#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?
中使用类似的东西
假设这是我现在的 url:
https://www.spiritfanfiction.com/perfil/depreciate
我需要提取 "depreciate" 并使用它转到 url:
https://www.spiritfanfiction.com/mensagens/post?usuario=depreciate
Ps:在这种情况下,我无法直接从 XPath 中提取。它必须在当前 url.
谢谢。
这是满足您愿望的代码 url。
newURL = driver.current_url.split(".com")[0]+".com/mensagens/post?usuario=" +driver.current_url.split("/")[-1]
# navigate to newURL
driver.get(newURL)
我使用 iMacros 已经很长时间了,我有一个代码可以提取文本并用它来创建我需要的特定 url。
事情是这样的:
#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?
中使用类似的东西假设这是我现在的 url:
https://www.spiritfanfiction.com/perfil/depreciate
我需要提取 "depreciate" 并使用它转到 url:
https://www.spiritfanfiction.com/mensagens/post?usuario=depreciate
Ps:在这种情况下,我无法直接从 XPath 中提取。它必须在当前 url.
谢谢。
这是满足您愿望的代码 url。
newURL = driver.current_url.split(".com")[0]+".com/mensagens/post?usuario=" +driver.current_url.split("/")[-1]
# navigate to newURL
driver.get(newURL)