Skip to main content

Web Scraping using Beautiful Soup (NEPSE LIVE DATA SCRAPING IN PYTHON)

from bs4 import BeautifulSoup import requests import csv

source = requests.get("http://nepalstock.com.np/").text soup = BeautifulSoup(source, 'lxml')
csv_file = open('nepse.csv','w')
csv_writer = csv.writer(csv_file) csv_writer.writerow(['Symbol', 'Values', 'Total Traded amount'])
marquee_tag = soup.find( 'div', class_="col-xs-10 col-md-10 col-sm-12").marquee.b
for span_tag in marquee_tag('span'):     span_tag.replace_with('')
for img_tag in marquee_tag('img'):     img_tag.replace_with('')
symbol_list = marquee_tag.text.split('( )')
all_symbols = [] short_name = [] per_share_value = [] total_traded_amount = [] a1 = [] a2 = [] a3 = []
for symbol in symbol_list:     symbol_name = symbol.replace(u'\xa0', u'')     all_symbols.append(symbol_name) all_symbols.pop()
a = len(all_symbols)
for i inrange(a):     a1.append(all_symbols[i].strip())     a2.append(a1[i].split(&…

Learn Python From Basics. Part 1!

Reference: 
https://www.amazon.com/Programming-Python-Complete-Introduction-Language/dp/0321680561

This is going to be a long session of python programming.
From this session, we are going to learn about basic python syntax and structures and then move on to the advanced topics.
I have divided python into eight different topics. In this blog, we will take a look at the first two pieces. I have tried to make this session as simple as possible and as much interactive as I could. So, what are we waiting for? Let's dive in! Feel free to comment on any part you find difficult.

The eight key pieces  to learn at first in Python are:
1. Data Types
2. Object References
3. Collection Data Types
4. Logical Operations
5. Control Flow Statements
6. Arithmetic Operators
7. Input/Output
8. Creating and Calling Functions

1. Data Types: 

There are several built-in data types in python. Here we are going to discuss some of them.
In python, the integer has no limit. It is only limited by the machine's memory. Example:
>>> print(2564899665123564896523166986689866 + 1)
2564899665123564896523166986689867
Both positive and negative whole numbers are int type. 
Python represents strings as well as Unicode characters (NOT LIMITED BY ASCII characters) in str type.
Examples:
668
274749234724398742379259694940597983988341048
"Saroj Blogs"
'Mark Summerfield'
'Helloo © ÷'
We can use square brackets to access items from a sequence. 
>>> "Pearson Python 3" [2]
'a'
 This is because the indexing of P starts from 0. 
For type conversion, we use this syntax:
               datatype (item)
Say we have to convert 45 to string then
>>> a = str(45)
>>>print(a)
45
>>>type(a)
<class 'str'>1. Data Types: 

2. Object References: 
In python, everything is an object (we will later discuss object). Essentially all the variables in Python are objects. So, object references and variables can be used interchangeably. Syntax: objectReference = value
Example:
      a = "apple"
      b = a
When we execute the code, an object of str type is created with text "apple" and object reference a. Similarly, the second statement creates object reference b and sets it to refer to the same object that is referred by a. Here the operator "=" binds objects to the object reference (or Variables).
>>> a = "apple"
>>> b = a
>>> print(a, b)
apple apple
























Comments

Popular posts from this blog

How to get GitHub Student Pack, Apply now

Git is a version control system. GitHub is a web-based hosting service for version control using git. You can save all the projects on GitHub. GitHub has given some benefits for students. They recently are providing the student development pack for the students to give access to developers tools for free. Some of these real world tools are too expensive for a student to use. So, for those students who love the education, this could be just great! To get students developer pack, we are going to follow these steps:
1. First you need to make an account on GitHub. Go to this link https://www.github.com/ and sign up for free. 2. After making an account on GitHub, visit the link https://education.github.com/pack/.
3. Click on “Get your pack” button.  4.Sign with GitHub with your username and password.  5. Click on the button “Yes, I’m a Student”.
6. Enter your name and verify your academic status. Add a photo of your identity card where it says “Drop file here or click to upload”. 
7. Enter your C…

Basic guidelines for Chess opening.

If you are reading this blog, you probably know how the pieces move in the game of chess. The player with the white pieces always moves first. The opening is generally considered complete when your rooks are connected. There are some basic principles to follow how to play efficiently. We should focus on the development of pieces. Here are top 10 opening rules for good chess opening:
We must attack the center of board. So, OPEN with a CENTER PAWN like e4, d4. While (e4d4e5d5) are generally regarded as the central squares, the same principle can sometimes be extended to the adjacent squares like (c4c5d3d6e3e6f4f5).DEVELOP pieces with threats. Always develop your Knights before Bishops. Develop knights to towards the center of board rather than side of board. When the knight is developed in the center, it could attack up to 8 squares. The real reason to develop Knights before Bishops is that Knight are shorter-range pieces, and it will take them a couple of moves to ge…

How to generate Golden Ratio by programming?

Golden ratio has been a fascinating topic for last more than 2400 years despite it does not have reliable evidence. Golden ratio is seen in the circle of Sunflower "flower". We can get golden ratio when we divide a line into two parts, the ratio of dividing the large part with small part is equal to the whole length divided by the longer part.

For a programmer it will be more fascinating to know how to code the golden ratio. The most easy way to do this is by using Fibonacci Series. We can use python code like this.




s = 0
a = 1
b = 1
for x in range(9999):
c = a + b
a = b
print (c/b)  #This is the golden ratio
b = c


Golden ratio occurs in nature in different forms. Some of the examples are:
1. Flower Petals
2. Seed Heads
3. Pine Cones
4. Shells
5. Spiral galaxies
6. Hurricanes
7. Fingers
8. Animal Bodies
9. DNA molecules

Thank you!
A blog by Saroj Bhattarai