Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 我想用翻译后的标签替换标签_Html_Selenium_Beautifulsoup_Replace_Tags - Fatal编程技术网

Html 我想用翻译后的标签替换标签

Html 我想用翻译后的标签替换标签,html,selenium,beautifulsoup,replace,tags,Html,Selenium,Beautifulsoup,Replace,Tags,我正在使用下面的代码翻译并用翻译后的标记替换标记,但失败了 相同的html在代码之后返回,没有任何更改 我想我不需要解释更多,因为这是一个简单的selenium和bs4代码。 我使用的是“翻译人员库”,但它不起作用,我也尝试先提取文本,然后再翻译,但它不起作用。所以这个方法是可行的,但我想要的是,用翻译后的标签替换原始标签 代码如下: from bs4 import BeautifulSoup, NavigableString, Tag import requests import time i

我正在使用下面的代码翻译并用翻译后的标记替换标记,但失败了

相同的html在代码之后返回,没有任何更改

我想我不需要解释更多,因为这是一个简单的selenium和bs4代码。 我使用的是“翻译人员库”,但它不起作用,我也尝试先提取文本,然后再翻译,但它不起作用。所以这个方法是可行的,但我想要的是,用翻译后的标签替换原始标签

代码如下:

from bs4 import BeautifulSoup, NavigableString, Tag
import requests
import time
import pandas as pd
import translators as ts
import json
import numpy as np
import regex
import selenium
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
from urllib3.filepost import choose_boundary
from shutil import which
import string






r=requests.get('https://neculaifantanaru.com/en/the-witchcraft-of-a-masterpieces-creator.html')
soup=BeautifulSoup(r.text, 'html.parser')


chrome_option = Options()
chrome_option.add_argument('--user-agent={Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36}')
chrome_option.add_argument("--start-maximized")
driver = webdriver.Chrome(options = chrome_option)
driver.get('https://www.google.com/search?q=english+to+romanian&rlz=1C1CHWL_enPK938PK938&oq=eng+to+ro&aqs=chrome.1.69i57j0i10i433j0j0i10l7.6087j0j7&sourceid=chrome&ie=UTF-8')  
time.sleep(7)

lst=[]
tlist=[]
articles = soup.find_all('p', {'class':"text_obisnuit"})
for a in articles:
    lst.append(a)




for tag in lst:

    driver.find_element_by_xpath('//*[@id="tw-source-text-ta"]').send_keys(str(tag))
    time.sleep(5)
    var=driver.find_element_by_xpath('//*[@id="tw-target-text"]/span').text

    driver.find_element_by_xpath('//*[@id="tw-source-text-ta"]').send_keys(Keys.CONTROL,'a')

    tlist.append(var)
    

for z,i in zip(tlist,articles):
    print(z)
    i=z




print(soup)
最后我也尝试了这个方法

for z,i in zip(tlist,articles):
print(z)
var1=i.replace_with(z)




print(soup)
我进一步尝试:

for z,i in zip(tlist,articles):
print(z)
i.string=z.text




print(soup)
请任何人指导我,如何用翻译后的标签替换原始标签