欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python3使用urllib示例取googletranslate(谷歌翻譯)

 更新時(shí)間:2014年01月23日 09:14:43   作者:  
這篇文章主要介紹了使用urllib取googletranslate(谷歌翻譯)的示例,通過這個(gè)谷歌翻譯示例學(xué)習(xí)python3中urllib的使用方法,

復(fù)制代碼 代碼如下:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# File Name : gt1.py
# Purpose :
# Creation Date : 1390366260
# Last Modified : Wed 22 Jan 2014 06:14:11 PM CST
# Release By : Doom.zhou


import urllib.request
import sys

typ = sys.getfilesystemencoding()

def translate(querystr, to_l="zh", from_l="en"):
    '''for google tranlate by doom
    '''
    C_agent = {'User-Agent': "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.165063 Safari/537.36 AppEngine-Google."}
    flag = 'class="t0">'
    tarurl = "http://translate.google.com/m?hl=%s&sl=%s&q=%s \
        " % (to_l, from_l, querystr.replace(" ", "+"))
    request = urllib.request.Request(tarurl, headers=C_agent)
    page = str(urllib.request.urlopen(request).read().decode(typ))
    target = page[page.find(flag) + len(flag):]
    target = target.split("<")[0]
    return target

print(translate("Hello world"))

相關(guān)文章

  • Python隨機(jī)數(shù)用法實(shí)例詳解【基于random模塊】

    Python隨機(jī)數(shù)用法實(shí)例詳解【基于random模塊】

    這篇文章主要介紹了Python隨機(jī)數(shù)用法,結(jié)合實(shí)例形式分析了基于random模塊的各種隨機(jī)數(shù)操作常用技巧,需要的朋友可以參考下
    2017-04-04
  • Python3.7安裝pyaudio教程解析

    Python3.7安裝pyaudio教程解析

    這篇文章主要介紹了Python3.7安裝pyaudio教程解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-07-07
  • Python文件去除注釋的方法

    Python文件去除注釋的方法

    這篇文章主要介紹了Python文件去除注釋的方法,涉及Python正則表達(dá)式及文件操作的相關(guān)技巧,需要的朋友可以參考下
    2015-05-05
  • django模型動(dòng)態(tài)修改參數(shù),增加 filter 字段的方式

    django模型動(dòng)態(tài)修改參數(shù),增加 filter 字段的方式

    這篇文章主要介紹了django模型動(dòng)態(tài)修改參數(shù),增加 filter 字段的方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-03-03
  • python commands模塊的適用方式

    python commands模塊的適用方式

    這篇文章主要介紹了python commands模塊的適用方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-02-02
  • Vs Code中8個(gè)好用的python 擴(kuò)展插件

    Vs Code中8個(gè)好用的python 擴(kuò)展插件

    這篇文章主要介紹了Vs Code中8個(gè)好用的python 擴(kuò)展插件,幫助大家更好的利用vs code進(jìn)行python開發(fā),感興趣的朋友可以了解下
    2020-10-10
  • 解決jupyter notebook啟動(dòng)后沒有token的坑

    解決jupyter notebook啟動(dòng)后沒有token的坑

    這篇文章主要介紹了解決jupyter notebook啟動(dòng)后沒有token的坑,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2021-04-04
  • 用tensorflow構(gòu)建線性回歸模型的示例代碼

    用tensorflow構(gòu)建線性回歸模型的示例代碼

    本篇文章主要介紹了用tensorflow構(gòu)建線性回歸模型的示例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-03-03
  • numpy中的norm()函數(shù)求范數(shù)實(shí)例

    numpy中的norm()函數(shù)求范數(shù)實(shí)例

    這篇文章主要介紹了numpy中的norm()函數(shù)求范數(shù)實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-02-02
  • 教你如何在Pytorch中使用TensorBoard

    教你如何在Pytorch中使用TensorBoard

    TensorBoard是TensorFlow中強(qiáng)大的可視化工具,今天通過本文給大家介紹如何在Pytorch中使用TensorBoard,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友一起看看吧
    2021-08-08

最新評(píng)論