import requests
import os
from lxml import etree
import pymysql

rootPath=r'E:\#siteDATA\english-word' #保存的根据路径,不同的平台需要修改



def myRequest(url):
    response = requests.get(url)
    response.encoding="utf-8"
    return response

"""
功能已完成，先插入单词数据，就可以了
"""
def eudic(word):
    realUrl="https://dict.eudic.net/dicts/en/"+word
    # response = requests.get(url=realUrl)
    # response.encoding="utf-8"
    response = myRequest(realUrl)

    #解析
    treeObj = etree.HTML(response.text)
    symbolText = treeObj.xpath('//*[@id="exp-head"]/div/span[1]/span[4]/text()')[0]
    fanyi= treeObj.xpath('//*[@id="ExpFCChild"]/ol/li')
    print(fanyi)
    fanyiText=""
    for li in fanyi:
        text = li.xpath('.//text()')
        te = "".join(text)
        fanyiText = fanyiText+te+"#"


    print(fanyiText)
    voiceSector = treeObj.xpath('//*[@id="exp-head"]/div/span[1]/a[2]/@data-rel')[0]
    voiceUrl="https://api.frdic.com/api/v2/speech/speakweb?"+voiceSector
    mp3response = myRequest(voiceUrl)
    mp3Path = saveMp3(word,mp3response,"usa")
    #保存 symbolText voiceRealUrl
    writeToMysql(word,symbolText,mp3Path,fanyiText,"usa")



#eudic('succeed')
readMysql()
import requests
import os
from lxml import etree
import pymysql

rootPath=r'E:\#siteDATA\english-word' #保存的根据路径,不同的平台需要修改



def myRequest(url):
    response = requests.get(url)
    response.encoding="utf-8"
    return response

"""
功能已完成，先插入单词数据，就可以了
"""
def eudic(word):
    realUrl="https://dict.eudic.net/dicts/en/"+word
    # response = requests.get(url=realUrl)
    # response.encoding="utf-8"
    response = myRequest(realUrl)

    #解析
    treeObj = etree.HTML(response.text)
    symbolText = treeObj.xpath('//*[@id="exp-head"]/div/span[1]/span[4]/text()')[0]
    fanyi= treeObj.xpath('//*[@id="ExpFCChild"]/ol/li')
    print(fanyi)
    fanyiText=""
    for li in fanyi:
        text = li.xpath('.//text()')
        te = "".join(text)
        fanyiText = fanyiText+te+"#"


    print(fanyiText)
    voiceSector = treeObj.xpath('//*[@id="exp-head"]/div/span[1]/a[2]/@data-rel')[0]
    voiceUrl="https://api.frdic.com/api/v2/speech/speakweb?"+voiceSector
    mp3response = myRequest(voiceUrl)
    mp3Path = saveMp3(word,mp3response,"usa")
    #保存 symbolText voiceRealUrl
    writeToMysql(word,symbolText,mp3Path,fanyiText,"usa")



#eudic('succeed')
readMysql()
#siteDATA\english-word' #保存的根据路径,不同的平台需要修改 功能已完成，先插入单词数据，就可以了 # response = requests.get(url=realUrl) # response.encoding="utf-8" #解析 #保存 symbolText voiceRealUrl #eudic('succeed')