Clean Up Extracting Google Translate Examples Text innertext & outertext

Dossfm0q

Banned User
Joined
Mar 9, 2009
Messages
570
Office Version
  1. 2019
Platform
  1. Windows
By using "Replace()" to remove unwanted strings from Extracting Google Translate Examples Text success with innerhtml and outerhtml while innertext & outertext have big Spacing between Lines

Ranges A1 B1 Bad
Ranges A2 B2 Good

VBA Code:
Sub Test()

Cells.Clear

ExtractExsamples "en", "ar", "man"

End Sub

Public Sub ExtractExsamples(FromLng, ToLng, StrText)

Dim IE As Object 'New InternetExplorer
Dim Url As String
Dim Doc As Object
Dim clipboard As Object


Set IE = CreateObject("InternetExplorer.Application")

Set clipboard = GetObject("New:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")

Url = "https://translate.google.com/?hl=en&tab=wT&authuser=0#view=home&op=translate&sl=" & FromLng & "&tl=" & ToLng & "&text=" & LCase(StrText)
With IE
.Visible = True
.navigate Url
While IE.ReadyState <> 4
DoEvents
Wend
Application.Wait (Now + TimeValue("0:00:01"))

Set Doc = IE.Document

    Set TransExamples = Doc.querySelector(".gt-cd.gt-cd-mex") '.getElementsByTagName(".gt-ex-text")' how to use like this

   
''''''to cleanup
Set TransNone = Doc.querySelector(".gt-ex-info")
Set quotationmark = Doc.querySelector(".gt-ex-quote")
Set AutTrnsByGl = Doc.querySelector(".gt-ex-mt")
Set EXtp = Doc.querySelector(".gt-ex-top")

On Error Resume Next

Getinnertext = Replace(Replace(Replace(Replace(TransExamples.innertext, TransNone.innertext, ""), quotationmark.innertext, ""), AutTrnsByGl.innertext, ""), EXtp.innertext, "")
Getoutertext = Replace(Replace(Replace(Replace(TransExamples.outertext, TransNone.outertext, ""), quotationmark.outertext, ""), AutTrnsByGl.outertext, ""), EXtp.outertext, "")
[A1] = Getinnertext ''Range("A1")
[B1] = Getoutertext ''Range("B1")


Getinnerhtml = Replace(Replace(Replace(Replace(TransExamples.innerhtml, TransNone.innerhtml, ""), quotationmark.innerhtml, ""), AutTrnsByGl.innerhtml, ""), EXtp.innerhtml, "")
Getinnerhtml = "<html lang=""en""><head><body>" & Getinnerhtml & "</body></html>"
clipboard.SetText Getinnerhtml
clipboard.PutInClipboard
[A2].PasteSpecial ''Range("A2")

Getouterhtml = Replace(Replace(Replace(Replace(TransExamples.outerHTML, TransNone.outerHTML, ""), quotationmark.outerHTML, ""), AutTrnsByGl.outerHTML, ""), EXtp.outerHTML, "")
Getouterhtml = "<html lang=""en""><head><body>" & Getouterhtml & "</body></html>"
clipboard.SetText Getouterhtml
clipboard.PutInClipboard
[B2].PasteSpecial 'Range("B2")

.Quit
End With
End Sub
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

Forum statistics

Threads
1,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top