Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

webscrapping with python

#Python program to scrape website 
#and save quotes from website
import requests
from bs4 import BeautifulSoup
import csv
   
URL = "http://www.values.com/inspirational-quotes"
r = requests.get(URL)
   
soup = BeautifulSoup(r.content, 'html5lib')
   
quotes=[]  # a list to store quotes
   
table = soup.find('div', attrs = {'id':'all_quotes'}) 
   
for row in table.findAll('div',
                         attrs = {'class':'col-6 col-lg-3 text-center margin-30px-bottom sm-margin-30px-top'}):
    quote = {}
    quote['theme'] = row.h5.text
    quote['url'] = row.a['href']
    quote['img'] = row.img['src']
    quote['lines'] = row.img['alt'].split(" #")[0]
    quote['author'] = row.img['alt'].split(" #")[1]
    quotes.append(quote)
   
filename = 'inspirational_quotes.csv'
with open(filename, 'w', newline='') as f:
    w = csv.DictWriter(f,['theme','url','img','lines','author'])
    w.writeheader()
    for quote in quotes:
        w.writerow(quote)
Comment

PREVIOUS NEXT
Code Example
Python :: how to get input with python 
Python :: how to find highest number in list without using max function python 
Python :: label change in tkinter 
Python :: opencv shift image python 
Python :: how to remove the last letter of a string python 
Python :: Python function to compute factorial of a number. 
Python :: python count occurrences of an item in a list 
Python :: types of dict comprehension 
Python :: how to get dictionary input from user in python 
Python :: get ip address py 
Python :: python sort multiple lists based on sorting of single list 
Python :: position in array python 
Python :: try except json decode error 
Python :: split python strings into pairs & complete uneven pairs 
Python :: add column in spark dataframe 
Python :: how to use label encoding in python 
Python :: matplotlib python background color 
Python :: Python program to implement linear search and take input. 
Python :: np append row 
Python :: tkinter filedialog get directory path 
Python :: display prime numbers between two intervals in python 
Python :: python find digits in string 
Python :: reverse element in a list in python 3 
Python :: make an android app with python 
Python :: seaborn pink green color palette python 
Python :: remove space characters from string in python 
Python :: Exit code: ENOENT. spawn /usr/bin/python ENOENT 
Python :: Matplotlib rotated xticklabels 
Python :: requests python3 example 
Python :: cors flask 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =