[Python3] Google translate google translate without using api

Preface

I thought I should use Google's translation API when I want to translate English sentences into Japanese with python, but it was charged (´ ・ ω ・ `) Then I thought that I should scrape and get the translation result! So I made it

environment

Python 3.4.3 :: Anaconda 2.3.0 (x86_64)

Required library

program

from selenium import webdriver
from bs4 import BeautifulSoup
import urllib.parse

english = 'As an app designer, you have the opportunity to deliver an extraordinary product that rises to the top of the App Store charts.'
url_text = "https://translate.google.co.jp/#en/ja/{0}".format(english)
url = urllib.parse.quote_plus(url_text, "/:?=&#")

driver = webdriver.PhantomJS()
driver.get(url)
html = driver.page_source
soup = BeautifulSoup(html,'html.parser')

print('English')
print(english)
print('Japanese')
print(soup.find(id='result_box').text)

When you want to convert from English to Japanese I think you can do it by replacing ʻen and jaof" https://translate.google.co.jp/#en/ja/{0} ".format (engish) of ʻurl_text. Other languages as well

What you are doing

It just stores the string specified by ʻenlish in ʻurl_text and converts spaces and double-byte characters to the format of ʻURL.

problem

Slow because I have to draw with PhantomJS Cannot be converted if the structure of the web page changes

Well ... If you complain like this, you can use the paid API.

Recommended Posts

[Python3] Google translate google translate without using api
Creating Google Spreadsheet using Python / Google Data API
Read English sentences by hitting Google Translate API with Python without using the distributed module
Google Drive Api Tips (Python)
Translate using googletrans in Python
Upload JPG file using Google Drive API in Python
[Python] Easy Google Translate app using Eel and Googletrans
[Python] Get insight data using Google My Business API
Speech transcription procedure using Python and Google Cloud Speech API
Speech file recognition by Google Speech API v2 using Python
Data acquisition using python googlemap api
[Python] Hit the Google Translation API
Inflating text data by retranslation using google translate in Python
Try using Pleasant's API (python / FastAPI)
Forcibly use Google Translate from python
Create Gmail in Python without API
Slice without using Python, colon (:). a.__getitem__ (slice (3,5)).
Get an English translation using python google translate selenium (memories)
Try using Python argparse's action API
Run Ansible from Python using API
Use Google Analytics API from Python
Play with YouTube Data API v3 using Google API Python Client
Stream speech recognition using Google Cloud Speech gRPC API on python3 on Mac!
Regularly upload files to Google Drive using the Google Drive API in Python
[SEO] Flow / sample code when using Google Analytics API in Python
Google Cloud Vision API sample for python
Mouse operation using Windows API in Python
Try using the Wunderlist API in Python
Try using the Kraken API in Python
[Beginner] Python web scraping using Google Colaboratory
Tweet using the Twitter API in Python
Get Google Fit API data in Python
Try using Python with Google Cloud Functions
Speech transcription procedure using Google Cloud Speech API
Get Youtube data in Python using Youtube Data API
Use Google Cloud Vision API from Python
I tried using UnityCloudBuild API from Python
Image collection using Google Custom Search API
Start using Python
Scraping using Python
Modulo without using%
How to display Map using Google Map API (Android)
Procedure to use TeamGant's WEB API (using python)
[Python] Get all comments using Youtube Data API
Run Google Analytics API (core v3) in python
Try using the BitFlyer Ligntning API in Python
Get image URL using Flickr API in Python
I tried using the Google Cloud Vision API
Tweet (API 1.1) on Google App Engine for Python
Let's judge emotions using Emotion API in Python
Recent ranking creation using Qiita API with Python
Manipulate objects using Blender 2.8's low-level Python API
Anonymous upload of images using Imgur API (using Python)
[Google Cloud Platform] Use Google Cloud API using API Client Library
Try using ChatWork API and Qiita API in Python
Try using the DropBox Core API in Python
I tried using Google Translate from Python and it was just too easy
[GCP] [Python] Deploy API serverless with Google Cloud Functions!
Operate Redmine using Python Redmine
Fibonacci sequence using Python
Data analysis using Python 0