0

after reading these in below, I still can't see the solution : Extract data from website via PHP php extract body tag content

after i using

file_get_contents("https://translate.google.com/#view=home&op=translate&sl=en&tl=fa&text=Help%20Me")

It seems it doesn't contain the words that I typed in box of translator(the words:Help Me)

How can i get all the data from start to end that contains the word that user(myself) typed?

TheFaultInOurStars
  • 3,464
  • 1
  • 8
  • 29
  • You are using website translator as an API which you shouldn’t (because there are likely Javascripts in that page that make requests to server for translation). You need an [SDK](https://github.com/googleapis/google-cloud-php-translate) to perform these kinds of tasks instead. – Daniel Protopopov Feb 17 '20 at 21:23

1 Answers1

2

Google Translate uses Javascript to read & display the translated text. It is not available in the source code. You can verify this by viewing the source of the URL you provided yourself (e.g. by copying view-source:https://translate.google.com/#view=home&op=translate&sl=en&tl=fa&text=Help%20Me into your address bar). It's also against their terms of service.

To access Google Translate programmatically you need to use the Cloud Translation API. This API provides $10/month of free usage, which is enough for most hobbyist projects.

Here is more information on pricing and quotas, and even a handy guide to using PHP with it.

Jake Lee
  • 7,549
  • 8
  • 45
  • 86
  • thank you very much, but why we can see the word in html(chrome or firefox or others) but we cant get that from php and text? i mean it should be something like a protocol or something that can get the data and send it to website and that we get the data from html... – TheFaultInOurStars Feb 22 '20 at 14:57
  • The protocol you just described exists. It's the API I linked! – Jake Lee Feb 22 '20 at 15:09