-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper.py
59 lines (48 loc) · 1.99 KB
/
helper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from selenium import webdriver
from bs4 import BeautifulSoup
import time
#from selenium.webdriver.firefox.options import Options
#from selenium.webdriver.firefox.service import Service
from webdriver_manager.chrome import ChromeDriverManager
def scrape_ieee(url):
#driver_path = '/usr/bin/chromedriver'
#options = webdriver.ChromeOptions()
#options.add_experimental_option('detach', True)
#service = webdriver.ChromeService(executable_path=driver_path)
#driver = webdriver.Chrome(service=service, options=options)
#driver = webdriver.Chrome(ChromeDriverManager().install())
driver = webdriver.PhantomJS()
driver.get(url)
time.sleep(0.5)
soup = BeautifulSoup(driver.page_source, 'html.parser')
raw = soup.find('div', {'class':'body-description'}).find_all('p')
full_text = ""
for i in raw:
full_text += i.text
driver.quit()
return full_text
def scrape_reuters(url):
#driver_path = '/home/vboxuser/Downloads/chromedriver-linux64/chromedriver'
#options = Options()
#options.add_argument("--headless")
#options.add_experimental_option('detach', True)
#service = webdriver.ChromeService(executable_path=driver_path)
#driver = webdriver.Chrome(service=service, options=options)
#service = Service(executable_path="/snap/bin/geckodriver")
#driver = webdriver.Firefox(service=service, options=options)
#driver_path = '/usr/bin/chromedriver'
#options = webdriver.ChromeOptions()
#options.add_experimental_option('detach', True)
#service = webdriver.ChromeService(executable_path=driver_path)
#driver = webdriver.Chrome(service=service, options=options)
#driver = webdriver.Chrome(ChromeDriverManager().install())
driver = webdriver.PhantomJS()
driver.get(url)
time.sleep(0.5)
soup = BeautifulSoup(driver.page_source, 'html.parser')
raw = soup.select('div[data-testid*="paragraph"]')
full_text = ""
for i in raw:
full_text += i.text
driver.quit()
return full_text