Created
July 17, 2020 08:12
-
-
Save CHARITH1995/f1017857653db9ee25ab4e9df2f6f1fb to your computer and use it in GitHub Desktop.
web scrapping libraries import
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 bs4 import BeautifulSoup | |
import time | |
from selenium import webdriver | |
import MySQLdb | |
from datetime import datetime | |
import csv | |
url = "http://sinhala.adaderana.lk/sinhala-hot-news.php" #this is website url | |
db = MySQLdb.connect(host="localhost", | |
user="root", | |
passwd="", | |
db="research", | |
charset='utf8', | |
use_unicode=True) | |
# create a Cursor object | |
cur = db.cursor() | |
driver = webdriver.Firefox(executable_path=r'D:\apps\anaconda\geckodriver.exe') #above website is a javascript enable one.Therefore we webdriver use. | |
driver.get(url) | |
time.sleep(5) | |
htmlSource = driver.page_source | |
soup = BeautifulSoup(htmlSource, 'lxml') | |
type(soup) | |
#title = soup.title | |
all_div = soup.find_all("div",{"class" : "news-story"}) #div tags depends on your website |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment