Created
November 25, 2019 07:11
-
-
Save jkotra/9de90f173ffa8138633040542b004211 to your computer and use it in GitHub Desktop.
Medium Scraper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from selenium import webdriver | |
from selenium.webdriver.firefox.options import Options | |
from bs4 import BeautifulSoup | |
class Scraper: | |
def __init__(self): | |
self.options = Options() | |
self.options.add_argument('--headless') | |
self.driver = webdriver.Firefox(options=self.options) | |
def get(self,link): | |
self.driver.get(link) | |
data = self.driver.execute_script('return document.body.innerHTML') | |
self.driver.close() | |
soup = BeautifulSoup(data, "lxml") | |
all_sections = soup.find_all("section") | |
for section in all_sections: | |
for paragraph in section.find_all({"h1","p"})[1:-1]: | |
print(paragraph.text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment