Skip to content

Instantly share code, notes, and snippets.

@CHARITH1995
Created July 17, 2020 08:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CHARITH1995/f1017857653db9ee25ab4e9df2f6f1fb to your computer and use it in GitHub Desktop.
Save CHARITH1995/f1017857653db9ee25ab4e9df2f6f1fb to your computer and use it in GitHub Desktop.
web scrapping libraries import
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