[Python] 纯文本查看 复制代码
from selenium import webdriver
wd=webdriver.Chrome(r'C:\chromedriver.exe')
wd.get('https://translate.google.cn/?sl=auto&tl=en&op=translate')
wd.implicitly_wait(9999999)
#import time
from time import sleep
import time
zanting=input('输入任意敲回车采集描述')
wd.execute_script('window.scrollTo(0,0)')
#回到网页顶部
fi=wd.find_element_by_xpath('//*[@id="yDmH0d"]/c-wiz/div/div[2]/c-wiz/div[2]/c-wiz/div[1]/div[2]/div[2]/c-wiz[2]/div[5]/div/div[1]/span[1]/span/span')
#保存描述
ygms=fi.text#保存英国描述
print('英国描述已采集')
an=wd.find_element_by_css_selector('[aria-label="更多目标语言"]')
an.click()#点击切换语言按钮
#time.sleep(5)
#an=wd.find_element_by_class_name('NMm5M')
#an.click()
#yu=wd.find_element_by_xpath('//*[@id="yDmH0d"]/c-wiz/div/div[2]/c-wiz/div[2]/c-wiz/div[3]/c-wiz/div[2]/div/div[3]/div/div[2]/div[106]/div[2]')
#yu.click()
#切换英语
sleep(0.5)
dy=wd.find_element_by_xpath('//*[@id="yDmH0d"]/c-wiz/div/div[2]/c-wiz/div[2]/c-wiz/div[3]/c-wiz/div[2]/div/div[3]/div/div[2]/div[19]')
#切换德语
sleep(0.5)
dy.click()
sleep(0.5)
c_s=1
while True:
sleep(1)
wd.execute_script('window.scrollTo(0,0)')
#回到网页顶部
fi=wd.find_element_by_xpath('//*[@id="yDmH0d"]/c-wiz/div/div[2]/c-wiz/div[2]/c-wiz/div[1]/div[2]/div[2]/c-wiz[2]/div[5]/div/div[1]/span[1]/span/span')
dgms=fi.text
#保存德国描述
if dgms!=ygms:
print('德国描述已采集')
break#如果保存的德国描述和英国不一致判断保存成功则退出循环
else:
print('德国描述第',c_s,'次未收集到')
c_s+=1
#通过 CSS Selector 选择单个元素的方法是
#find_element_by_css_selector(CSS Selector参数)
sleep(0.5)
an.click()
fy=wd.find_element_by_xpath('//*[@id="yDmH0d"]/c-wiz/div/div[2]/c-wiz/div[2]/c-wiz/div[3]/c-wiz/div[2]/div/div[3]/div/div[2]/div[21]/div[2]')
#切换法语
sleep(0.5)
fy.click()
#fy.click()
sleep(0.5)
c_s=1
while True:
sleep(1)
wd.execute_script('window.scrollTo(0,0)')
#回到网页顶部
fi=wd.find_element_by_xpath('//*[@id="yDmH0d"]/c-wiz/div/div[2]/c-wiz/div[2]/c-wiz/div[1]/div[2]/div[2]/c-wiz[2]/div[5]/div/div[1]/span[1]/span/span')
fgms=fi.text#保存法国翻译
if fgms!=dgms:
print('法国描述已采集')
break#如果法国翻译不等于德国翻译则跳出循环
else:
print('法国描述第',c_s,'次未收集到')
c_s+=1
#//*[@id="yDmH0d"]/c-wiz/div/div[2]/c-wiz/div[2]/c-wiz/div[1]/div[2]/div[2]/c-wiz[2]/div[5]/div/div[1]/span[1]/span/span
sleep(0.5)
an.click()
idly=wd.find_element_by_xpath('//*[@id="yDmH0d"]/c-wiz/div/div[2]/c-wiz/div[2]/c-wiz/div[3]/c-wiz/div[2]/div/div[3]/div/div[2]/div[100]/div[2]')
#切换意大利语
sleep(0.5)
idly.click()
sleep(0.5)
c_s=1
while True:
sleep(1)
wd.execute_script('window.scrollTo(0,0)')
#回到网页顶部
fi=wd.find_element_by_xpath('//*[@id="yDmH0d"]/c-wiz/div/div[2]/c-wiz/div[2]/c-wiz/div[1]/div[2]/div[2]/c-wiz[2]/div[5]/div/div[1]/span[1]/span/span')
idlms=fi.text
if idlms!=fgms:
print('意大利描述已采集')
break
else:
print('意大利描述第',c_s,'次未收集到')
c_s+=1
sleep(0.5)
an.click()
xbyy=wd.find_element_by_xpath('//*[@id="yDmH0d"]/c-wiz/div/div[2]/c-wiz/div[2]/c-wiz/div[3]/c-wiz/div[2]/div/div[3]/div/div[2]/div[91]/div[2]')
#切换西班牙语
sleep(0.5)
xbyy.click()
sleep(0.5)
c_s=1
while True:
sleep(1)
wd.execute_script('window.scrollTo(0,0)')
#回到网页顶部
fi=wd.find_element_by_xpath('//*[@id="yDmH0d"]/c-wiz/div/div[2]/c-wiz/div[2]/c-wiz/div[1]/div[2]/div[2]/c-wiz[2]/div[5]/div/div[1]/span[1]/span/span')
xbyms=fi.text
if xbyms!=idlms:
print('西班牙描述已采集')
break
else:
print('西班牙描述第',c_s,'次未收集到')
c_s+=1
#print(ygms,dgms,fgms,idlms,xbyms,sep='\n')
print('描述采集完毕')
wd.execute_script('window.scrollTo(0,0)')
#回到网页顶部
sleep(0.5)
an.click()
yu=wd.find_element_by_xpath('//*[@id="yDmH0d"]/c-wiz/div/div[2]/c-wiz/div[2]/c-wiz/div[3]/c-wiz/div[2]/div/div[3]/div/div[2]/div[106]/div[2]')
sleep(0.5)
yu.click()
#切换英语
wd.execute_script('window.scrollTo(0,0)')
#回到网页顶部
sleep(0.2)
qingchujian=wd.find_element_by_xpath('//*[@id="yDmH0d"]/c-wiz/div/div[2]/c-wiz/div[2]/c-wiz/div[1]/div[2]/div[2]/c-wiz[1]/span/span/div/textarea')
#清除键
sleep(0.1)
qingchujian.clear()
#清空描述,方便你接下来输入卖点
#===================================================================================================================================================================
#采集卖点
zanting=input('输入任意敲回车采集卖点')
wd.execute_script('window.scrollTo(0,0)')
#回到网页顶部
fi=wd.find_element_by_xpath('//*[@id="yDmH0d"]/c-wiz/div/div[2]/c-wiz/div[2]/c-wiz/div[1]/div[2]/div[2]/c-wiz[2]/div[5]/div/div[1]/span[1]/span/span')
#保存描述
ygmd=fi.text#保存英国描述
print('英国卖点已采集')
an=wd.find_element_by_css_selector('[aria-label="更多目标语言"]')
an.click()#点击切换语言按钮
#time.sleep(5)
#an=wd.find_element_by_class_name('NMm5M')
#an.click()
#yu=wd.find_element_by_xpath('//*[@id="yDmH0d"]/c-wiz/div/div[2]/c-wiz/div[2]/c-wiz/div[3]/c-wiz/div[2]/div/div[3]/div/div[2]/div[106]/div[2]')
#yu.click()
#切换英语
sleep(0.5)
dy=wd.find_element_by_xpath('//*[@id="yDmH0d"]/c-wiz/div/div[2]/c-wiz/div[2]/c-wiz/div[3]/c-wiz/div[2]/div/div[3]/div/div[2]/div[19]')
#切换德语
sleep(0.5)
dy.click()
sleep(0.5)
c_s=1
while True:
sleep(1)
wd.execute_script('window.scrollTo(0,0)')
#回到网页顶部
fi=wd.find_element_by_xpath('//*[@id="yDmH0d"]/c-wiz/div/div[2]/c-wiz/div[2]/c-wiz/div[1]/div[2]/div[2]/c-wiz[2]/div[5]/div/div[1]/span[1]/span/span')
dgmd=fi.text
#保存德国描述
if dgmd!=ygmd:
print('德国卖点已采集')
break#如果保存的德国描述和英国不一致判断保存成功则退出循环
else:
print('德国卖点第',c_s,'次未收集到')
c_s+=1
#通过 CSS Selector 选择单个元素的方法是
#find_element_by_css_selector(CSS Selector参数)
an.click()
sleep(0.5)
fy=wd.find_element_by_xpath('//*[@id="yDmH0d"]/c-wiz/div/div[2]/c-wiz/div[2]/c-wiz/div[3]/c-wiz/div[2]/div/div[3]/div/div[2]/div[21]/div[2]')
#切换法语
sleep(0.5)
fy.click()
#fy.click()
sleep(0.5)
c_s=1
while True:
sleep(1)
wd.execute_script('window.scrollTo(0,0)')
#回到网页顶部
fi=wd.find_element_by_xpath('//*[@id="yDmH0d"]/c-wiz/div/div[2]/c-wiz/div[2]/c-wiz/div[1]/div[2]/div[2]/c-wiz[2]/div[5]/div/div[1]/span[1]/span/span')
fgmd=fi.text#保存法国翻译
if fgmd!=dgmd:
print('法国卖点已采集')
break#如果法国翻译不等于德国翻译则跳出循环
else:
print('法国卖点第',c_s,'次未收集到')
c_s+=1
#//*[@id="yDmH0d"]/c-wiz/div/div[2]/c-wiz/div[2]/c-wiz/div[1]/div[2]/div[2]/c-wiz[2]/div[5]/div/div[1]/span[1]/span/span
an.click()
sleep(0.5)
idly=wd.find_element_by_xpath('//*[@id="yDmH0d"]/c-wiz/div/div[2]/c-wiz/div[2]/c-wiz/div[3]/c-wiz/div[2]/div/div[3]/div/div[2]/div[100]/div[2]')
#切换意大利语
sleep(0.5)
idly.click()
sleep(0.5)
c_s=1
while True:
sleep(1)
wd.execute_script('window.scrollTo(0,0)')
#回到网页顶部
fi=wd.find_element_by_xpath('//*[@id="yDmH0d"]/c-wiz/div/div[2]/c-wiz/div[2]/c-wiz/div[1]/div[2]/div[2]/c-wiz[2]/div[5]/div/div[1]/span[1]/span/span')
idlmd=fi.text
if idlmd!=fgmd:
print('意大利卖点已采集')
break
else:
print('意大利卖点第',c_s,'次未收集到')
c_s+=1
an.click()
sleep(0.5)
xbyy=wd.find_element_by_xpath('//*[@id="yDmH0d"]/c-wiz/div/div[2]/c-wiz/div[2]/c-wiz/div[3]/c-wiz/div[2]/div/div[3]/div/div[2]/div[91]/div[2]')
#切换西班牙语
sleep(0.5)
xbyy.click()
sleep(0.5)
c_s=1
while True:
sleep(1)
wd.execute_script('window.scrollTo(0,0)')
#回到网页顶部
fi=wd.find_element_by_xpath('//*[@id="yDmH0d"]/c-wiz/div/div[2]/c-wiz/div[2]/c-wiz/div[1]/div[2]/div[2]/c-wiz[2]/div[5]/div/div[1]/span[1]/span/span')
xbymd=fi.text
if xbymd!=idlmd:
print('西班牙卖点已采集')
break
else:
print('西班牙卖点第',c_s,'次未收集到')
c_s+=1
print('卖点采集完毕')
#======================================================================================================================================================
#print(ygms,dgms,fgms,idlms,xbyms,sep='\n')
#print(ygmd,dgmd,fgmd,idlmd,xbymd,sep='\n')
while True:
hmd=input('输入')
if hmd=='y':
print(ygms,'分隔',ygmd,sep='\n')
elif hmd=='d':
print(dgms,'分隔',dgmd,sep='\n')
elif hmd=='f':
print(fgms,'分隔',fgmd,sep='\n')
elif hmd=='i':
print(idlms,'分隔',idlmd,sep='\n')
elif hmd=='x':
print(xbyms,'分隔',xbymd,sep='\n')