python - 是否有可能通过 selenium 自动化将 HTML 标记插入驻留在服务器上的文件中?
问题描述
我创建了简单的自动化,它将首先读取读取的子域文件夹,然后进入其中,然后查找特定的 html 文件。如果它会找到它(即:.html)然后编辑它,我想在该文件的某处添加特定标签,但我无法做到。
staticWord = "Hair"
htmlTag = "<a href='"+ staticRandomPathList[0] + "'>" + staticWord + "</a>"
print(htmlTag)
# Now on we are working statically
folderfound = 0
filefound = 0
for domainNameFolder in range(len(staticRandomPathList)):
subDomainSelectedFilesAddress = driver.find_element(By.XPATH,"//table/tbody/tr[" + str(domainNameFolder + 1) + "]/td[" + str(1) + "]")
subDomainName = new_list[domainNameFolder] + '.' + domain_list[domain_variable]
if subDomainSelectedFilesAddress.text == "logs" or subDomainSelectedFilesAddress.text == "public_html":
continue
else:
if subDomainSelectedFilesAddress.text == "test1.testlab.com":
action = ActionChains(driver)
action.double_click(subDomainSelectedFilesAddress).perform()
time.sleep(1)
for file in range(0, 10):
time.sleep(1)
selectedFile = driver.find_element(By.XPATH, "//table/tbody/tr[" + str(
file + 1) + "]/td[" + str(1) + "]")
if selectedFile.text == "5.html":
selectedFile.click()
editFile = driver.find_element(By.XPATH, "//a[@ng-click='showHTMLEditorModal()']")
editFile.click()
# addHtmlTag = WebDriverWait(driver, 20).until(
# EC.visibility_of_element_located((By.CLASS_NAME, "ace_content")))
# insertAnchorTag = driver.find_element(By.CLASS_NAME, "ace_content")
# insertAnchorTag.click()
#
time.sleep(2)
textinput = driver.find_element(By.CLASS_NAME, "ace_text-layer")
print(textinput.text)
gettingTextFromServer = textinput.text
Html_file = open("HTMLParsing.html", "w")
newHTMLFile = Html_file.write(gettingTextFromServer)
html = newHTMLFile
print(html)
# soup = Soup(html)
# bodyTag = soup.find('body')
# anchor = soup.new_tag('a')
# anchor['href'] = staticRandomPathList[0]
# bodyTag.insert(anchor)
Html_file.close()
# print(insertAnchorTag.text)
# mapHTMLTag = driver.find_element(By.ID, "id='htmlEditorContent'")
# mapHTMLTag.send_keys(htmlTag)
# addHtmlTag.send_keys(htmlTag)
filefound = 1
break
else:
continue
if filefound == 1:
break
folderfound = 1
break
else:
continue
print("Successfully Outside Loop")
我附上了图片,这样您就可以看到我想要放置该标签的位置。
解决方案
推荐阅读
- python - 链式模运算的最大值
- zabbix - 有没有办法在脚本中不提供用户名和密码的情况下登录 zabbix API
- android - 构建 QT Android 应用程序:..i686-linux-android-g++:没有这样的文件或目录
- spring - Spring-boot:使用 mvn 激活多个配置文件
- javascript - 滑动特定位置的详细信息应该存储在本地存储中吗?
- java - 如何知道元素是否包含命名空间(xmlns)?
- javascript - 使用图像之间的适当间距自定义 Slick 滑块设计
- wordpress - woocommerce_update_product 操作 – 每次产品更新仅触发一次
- reactjs - 如何使用带有突变和图像上传的异步功能反应js
- r - R为数据框列表创建一个循环