Dec-24-2018, 02:43 PM
Hi everyone,
First of all merry Christmas to all of you :D
Now, my issue is that : I'm trying to script something that allow me to scrape data from a bi-lingual web page to translate and store translations in a unique list (for after that put all that in a .xlsx page but not for now lol :p).
For example, from English to French :
With the word "house" generate his French translation in a list : ['maison', 'demeure', 'rédisence']
After this fist loop, search the translation of an other word.
For instance, "good", which will output the translation in list format : ['bon', 'bien', 'bonne']
And so on until I've finished my translations.
At that time, I would like to do is to gathered all of list lists in one list, like this : [['maison', 'demeure', 'rédisence'], ['bon', 'bien', 'bonne']]
But I didn't succeed to do that... I've tried so many way that I've forgotten what I've tried lol ^^' can anyone help me please ? :)
What my script does, is only printing the list of the last word translated but I would like to print all of them in one list like above :/
My piece of code here :
Please be indulgent with me, I'm new in programming and I've done all of this with Youtube and Google ^^'
Thank you very much :)
First of all merry Christmas to all of you :D
Now, my issue is that : I'm trying to script something that allow me to scrape data from a bi-lingual web page to translate and store translations in a unique list (for after that put all that in a .xlsx page but not for now lol :p).
For example, from English to French :
With the word "house" generate his French translation in a list : ['maison', 'demeure', 'rédisence']
After this fist loop, search the translation of an other word.
For instance, "good", which will output the translation in list format : ['bon', 'bien', 'bonne']
And so on until I've finished my translations.
At that time, I would like to do is to gathered all of list lists in one list, like this : [['maison', 'demeure', 'rédisence'], ['bon', 'bien', 'bonne']]
But I didn't succeed to do that... I've tried so many way that I've forgotten what I've tried lol ^^' can anyone help me please ? :)
What my script does, is only printing the list of the last word translated but I would like to print all of them in one list like above :/
My piece of code here :
Please be indulgent with me, I'm new in programming and I've done all of this with Youtube and Google ^^'
from urllib.request import Request, urlopen from lxml import html while True: # Open and save web page data word_to_translate = input('Quel est le mot à traduire ? ') if word_to_translate == 'stop': break url = "https://context.reverso.net/translation/dutch-french/" + word_to_translate headers = {"User-Agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36"} req = Request(url, headers=headers) openlink = urlopen(req) parsed_page = html.parse(openlink) openlink.close() # Select accurate data on the web page data found and clean it extracted_paragraphs = parsed_page.xpath("//a[@lang='fr']") plain_paragraphs = [] for every_coded_paragraph in extracted_paragraphs: decoded_paragraphs = every_coded_paragraph.text_content() plain_paragraphs.append(decoded_paragraphs) # Delete space from cleansed data final_list = [] for word in plain_paragraphs: final_list.append(word.strip()) print(final_list) # Gather all results in one list ??? copied_list = final_list.copy() pre_gathered_list = [] gathered_list = pre_gathered_list.append(copied_list) print(gathered_list)