Hướng dẫn extract data from rtf file python - trích xuất dữ liệu từ tệp rtf python

Đã hỏi 2 năm, 9 tháng trước 2 years, 9 months ago

Đã xem 1k lần 1k times

-1

Mới! Lưu câu hỏi hoặc câu trả lời và sắp xếp nội dung yêu thích của bạn. Tìm hiểu thêm.
Learn more.

Tôi cần trích xuất dữ liệu bảng từ các tệp RTF, nhưng dường như tôi không thể nhận được bất kỳ giải pháp nào liên quan đến điều này. Bất cứ ai cũng có thể đề xuất một giải pháp hoặc đã làm điều này trước đây và sẵn sàng cho tôi thấy Dawae? Tôi hiện đang khám phá để thay đổi những gì tôi định nghĩa là bắt đầu và kết thúc bảng thành một cái gì đó giống như một vòng tròn.

Tôi chỉ bắt đầu bắt đầu từ một cái gì đó giống như

\par \ltrrow}

Nhưng vào cuối bảng, dường như tôi không thể tìm thấy một cú pháp phù hợp ....

Cảm ơn trước. :)

hỏi ngày 14 tháng 1 năm 2020 lúc 1:04Jan 14, 2020 at 1:04

Dưới đây là một ví dụ về việc chuyển đổi định dạng RTF thành bản rõ bằng cách sử dụng regex

import re

text = r"{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 MS Shell Dlg 2;}{\f1\fnil MS Shell Dlg 2;}} {\colortbl ;\red0\green0\blue0;} {\*\generator Msftedit 5.41.15.1507;}\viewkind4\uc1\pard\tx720\cf1\f0\fs20 can u send me info for the call plsssss\f1\par }"

x = re.sub(r"{\*?\\.+(;})|\s?\\[A-Za-z0-9]+|\s?{\s?\\[A-Za-z0-9]+\s?|\s?}\s?", "", text)
print(x)

Đã trả lời ngày 14 tháng 1 năm 2020 lúc 8:56Jan 14, 2020 at 8:56

Hướng dẫn extract data from rtf file python - trích xuất dữ liệu từ tệp rtf python

Tôi có một số lượng rất lớn các tệp .rtf lớn, từ đó tôi muốn trích xuất dữ liệu bảng. Hiện tại tôi đang lặp lại các tệp và sử dụng pandas '.read_html để kéo các bảng ra.

Nó ổn, nhưng nó rất chậm. Có ai biết cách nhanh hơn để trích xuất dữ liệu không?

 [1] "I am happy to join with you today in what will go down in history as the greatest demonstration for freedom in the history of our nation."                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
 [2] "Five score years ago, a great American, in whose symbolic shadow we stand today, signed the Emancipation Proclamation. This momentous decree came as a great beacon light of hope to millions of Negro slaves who had been seared in the flames of withering injustice. It came as a joyous daybreak to end the long night of their captivity."                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
 [3] "But 100 years later, the Negro still is not free. One hundred years later, the life of the Negro is still sadly crippled by the manacles of segregation and the chains of discrimination. One hundred years later, the Negro lives on a lonely island of poverty in the midst of a vast ocean of material prosperity. One hundred years later, the Negro is still languished in the corners of American society and finds himself an exile in his own land. And so we've come here today to dramatize a shameful condition."                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
 [4] "In a sense we've come to our nation's capital to cash a check. When the architects of our republic wrote the magnificent words of the Constitution and the Declaration of Independence, they were signing a promissory note to which every American was to fall heir. This note was a promise that all men -- yes, black men as well as white men -- would be guaranteed the unalienable rights of life, liberty, and the pursuit of happiness."                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
 [5] "It is obvious today that America has defaulted on this promissory note insofar as her citizens of color are concerned. Instead of honoring this sacred obligation, America has given the Negro people a bad check, a check that has come back marked \"insufficient funds.\""                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
 [6] "But we refuse to believe that the bank of justice is bankrupt. We refuse to believe that there are insufficient funds in the great vaults of opportunity of this nation. And so we've come to cash this check, a check that will give us upon demand the riches of freedom and security of justice. We have also come to this hallowed spot to remind America of the fierce urgency of now. This is no time to engage in the luxury of cooling off or to take the tranquilizing drug of gradualism. Now is the time to make real the promises of democracy. Now is the time to rise from the dark and desolate valley of segregation to the sunlit path of racial justice. Now is the time to lift our nation from the quicksands of racial injustice to the solid rock of brotherhood. Now is the time to make justice a reality for all of God's children."                                                                                                                                                   
 [7] "It would be fatal for the nation to overlook the urgency of the moment. This sweltering summer of the Negro's legitimate discontent will not pass until there is an invigorating autumn of freedom and equality. 1963 is not an end but a beginning. Those who hoped that the Negro needed to blow off steam and will now be content will have a rude awakening if the nation returns to business as usual. There will be neither rest nor tranquility in America until the Negro is granted his citizenship rights. The whirlwinds of revolt will continue to shake the foundations of our nation until the bright day of justice emerges.<U+00A0>"                                                                                                                                                                                                                                                                                                                                                            
 [8] "But there is something that I must say to my people who stand on the warm threshold which leads into the palace of justice. In the process of gaining our rightful place we must not be guilty of wrongful deeds. Let us not seek to satisfy our thirst for freedom by drinking from the cup of bitterness and hatred. We must forever conduct our struggle on the high plane of dignity and discipline. We must not allow our creative protest to degenerate into physical violence. Again and again we must rise to the majestic heights of meeting physical force with soul force. The marvelous new militancy which has engulfed the Negro community must not lead us to a distrust of all white people, for many of our white brothers, as evidenced by their presence here today, have come to realize that their destiny is tied up with our destiny. And they have come to realize that their freedom is inextricably bound to our freedom. We cannot walk alone."                                      
 [9] "As we walk, we must make the pledge that we shall always march ahead. We cannot turn back. There are those who are asking the devotees of civil rights, \"When will you be satisfied?\" We can never be satisfied as long as the Negro is the victim of the unspeakable horrors of police brutality. We can never be satisfied as long as our bodies, heavy with the fatigue of travel, cannot gain lodging in the motels of the highways and the hotels of the cities. We cannot be satisfied as long as the Negro's basic mobility is from a smaller ghetto to a larger one. We can never be satisfied as long as our children are stripped of their selfhood and robbed of their dignity by signs stating \"for whites only.\" We cannot be satisfied as long as a Negro in Mississippi cannot vote and a Negro in New York believes he has nothing for which to vote. No, no we are not satisfied and we will not be satisfied until justice rolls down like waters and righteousness like a mighty stream."
[10] "I am not unmindful that some of you have come here out of great trials and tribulations. Some of you have come fresh from narrow jail cells. Some of you have come from areas where your quest for freedom left you battered by storms of persecution and staggered by the winds of police brutality. You have been the veterans of creative suffering. Continue to work with the faith that unearned suffering is redemptive."                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
[11] "Go back to Mississippi, go back to Alabama, go back to South Carolina, go back to Georgia, go back to Louisiana, go back to the slums and ghettos of our northern cities, knowing that somehow this situation can and will be changed."                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
[12] "Let us not wallow in the valley of despair. I say to you today my friends -- so even though we face the difficulties of today and tomorrow, I still have a dream. It is a dream deeply rooted in the American dream."                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
[13] "I have a dream that one day this nation will rise up and live out the true meaning of its creed: \"We hold these truths to be self-evident, that all men are created equal.\""                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
[14] "I have a dream that one day on the red hills of Georgia the sons of former slaves and the sons of former slave owners will be able to sit down together at the table of brotherhood."                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
[15] "I have a dream that one day even the state of Mississippi, a state sweltering with the heat of injustice, sweltering with the heat of oppression, will be transformed into an oasis of freedom and justice."                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
[16] "I have a dream that my four little children will one day live in a nation where they will not be judged by the color of their skin but by the content of their character."                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
[17] "I have a dream today."                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
[18] "I have a dream that one day down in Alabama, with its vicious racists, with its governor having his lips dripping with the words of interposition and nullification -- one day right there in Alabama little black boys and black girls will be able to join hands with little white boys and white girls as sisters and brothers."                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
[19] "I have a dream today."                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
[20] "I have a dream that one day every valley shall be exalted, and every hill and mountain shall be made low, the rough places will be made plain, and the crooked places will be made straight, and the glory of the Lord shall be revealed and all flesh shall see it together."                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  
[21] "This is our hope. This is the faith that I go back to the South with. With this faith we will be able to hew out of the mountain of despair a stone of hope. With this faith we will be able to transform the jangling discords of our nation into a beautiful symphony of brotherhood. With this faith we will be able to work together, to pray together, to struggle together, to go to jail together, to stand up for freedom together, knowing that we will be free one day."                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              
[22] "This will be the day, this will be the day when all of God's children will be able to sing with new meaning \"My country 'tis of thee, sweet land of liberty, of thee I sing. Land where my father's died, land of the Pilgrim's pride, from every mountainside, let freedom ring!\""                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
[23] "And if America is to be a great nation, this must become true. And so let freedom ring from the prodigious hilltops of New Hampshire. Let freedom ring from the mighty mountains of New York. Let freedom ring from the heightening Alleghenies of Pennsylvania."                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
[24] "Let freedom ring from the snow-capped Rockies of Colorado. Let freedom ring from the curvaceous slopes of California."                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          
[25] "But not only that; let freedom ring from Stone Mountain of Georgia."                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
[26] "Let freedom ring from Lookout Mountain of Tennessee."                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
[27] "Let freedom ring from every hill and molehill of Mississippi -- from every mountainside."                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
[28] "Let freedom ring. And when this happens, and when we allow freedom ring -- when we let it ring from every village and every hamlet, from every state and every city, we will be able to speed up that day when all of God's children -- black men and white men, Jews and Gentiles, Protestants and Catholics -- will be able to join hands and sing in the words of the old Negro spiritual: \"Free at last! Free at last! Thank God Almighty, we are free at last!\""                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         
[29] ""                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
[30] ""                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Làm cách nào để giải nén tệp RTF?

Mở tệp trong trình xử lý văn bản, chọn văn bản mong muốn và sao chép và dán nó vào tài liệu văn bản. Ví dụ: tạo một tài liệu văn bản mới trong Notepad, sau đó mở tài liệu RTF bằng Word và chọn một vài câu bằng cách giữ nút bên trái của chuột khi bạn tô sáng chúng.. For example, create a new text document in NotePad, then open the RTF document in Word and select a few sentences by holding the left button of the mouse down as you highlight them.

Làm cách nào để đọc một tệp RTF trong Python?

Đọc thế nào ...
với Open ('yourfile.rtf', 'r') dưới dạng tệp: text = file.read () in (văn bản) xxxxxxxxxx.với Open ('yourfile.rtf', 'r') dưới dạng tệp: ....
xxxxxxxxxxx.Với Open ("YourFile.Rtf") là Infile: Đối với dòng trong Infile: ....
xxxxxxxxxxx.từ Striprtf ..

Làm thế nào để bạn chuyển đổi RTF thành văn bản trong Python?

Cách chuyển đổi một số RTF thành TXT..
Cài đặt 'Aspose.....
Thêm một tham chiếu thư viện (nhập thư viện) vào dự án Python của bạn ..
Mở tệp RTF nguồn trong Python ..
Chuyển đổi một số tệp RTF thành TXT trong vài giây ..
Gọi phương thức 'append_document ()', chuyển tên tệp đầu ra với phần mở rộng TXT ..

Làm cách nào để chuyển đổi RTF thành CSV?

Cách chuyển đổi RTF thành CSV..
Tải lên (các) tệp RTF Chọn các tệp từ máy tính, Google Drive, Dropbox, URL hoặc bằng cách kéo nó trên trang ..
Chọn "To CSV" Chọn CSV hoặc bất kỳ định dạng nào khác bạn cần do kết quả (hơn 200 định dạng được hỗ trợ).
Tải xuống CSV của bạn ..