davidmezzetti commited on
Commit
a4aec71
1 Parent(s): 3dd67db

Create textractor.py

Browse files
Files changed (1) hide show
  1. textractor.py +25 -0
textractor.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Textractor module
3
+ """
4
+
5
+ import requests
6
+
7
+ from bs4 import BeautifulSoup
8
+
9
+ from txtai.pipeline.segmentation import Segmentation
10
+
11
+ class Textractor(Segmentation):
12
+ """
13
+ Extracts text from files.
14
+ """
15
+
16
+ def __init__(self, sentences=False, lines=False, paragraphs=False, minlength=None, join=False):
17
+ super().__init__(sentences, lines, paragraphs, minlength, join)
18
+
19
+ def text(self, text):
20
+ # text is a url
21
+ response = requests.get(text)
22
+ html = response.text
23
+
24
+ soup = BeautifulSoup(html, features="html.parser")
25
+ return soup.get_text()