소스 코드를 기록하는 남자

'분류 전체보기'에 해당되는 글 46건

  1. JavaScript - Hoisting
  2. JavaScript - window.onload
  3. JavaScript - Escape character, Operator
  4. JavaScript - Datatype
  5. What is JavaScript?
  6. How to crawl a webPage by python (BeautifulSoup)

JavaScript - Hoisting

JavaScript

In JavaScript, there is a rule for Declaration.

 

Every variable will be hoisted to top. 

 

Remember! Just Declaration, Not a value

 

<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>호이스팅 :: Hoisting</title>
<script type="text/javascript">
//1. hoisting
 	doSomething();
	
	function doSomething() { 
		alert("not defined : "+some); //undefined
	
		var some = "WellBeing";
		
		alert("defined : "+some); //WellBeing
	}; 
//2. Global Variable
var name = "James";
function showName(){
	var name = "Gosling";
	console.log(name);
}
console.log(name);
showName();
</script>
</head>
<body>

</body>
</html>

'JavaScript' 카테고리의 다른 글

JavaScript - Function Executing Process  (0) 2019.09.14
JavaScript - Global Variable  (0) 2019.09.14
JavaScript - window.onload  (0) 2019.09.14
JavaScript - Escape character, Operator  (0) 2019.09.14
JavaScript - Datatype  (0) 2019.09.14

JavaScript - window.onload

JavaScript

What is window.onload?

1. A function excutes after All contents are loaded.

 

2. the only one window.onload exists in a document

 

3. it is possible using onload to body tag. for this case, window.onload is ignored. 
   priority ( body tag onload > window.onload )

 

<!-- 
window.onload = function(){}
1. html 문서에 포함된 모든 콘텐츠가 로드된 후에 실행하는 함수
2. 동일한 문서에 window.onload 는 단 하나만 존재해야한다.
3. body 태그에도 onload 속성을 지정할 수 있는데 이때 window.onload 속성은 무시된다.
 -->
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script type="text/javascript">

	window.onload = function(){	alert("First window.onload");	};
	window.onload = function(){	alert("Second window.onload");	};
	
	/* If using onloads method, last onload will excute (Overriding) */
	
	/* jquery*/
	$(document).ready(function() {
		alert("First ready..");
	});

	$(document).ready(function() {
		alert("Second ready..");
	});
	
	
</script>
</head>
<!-- <body onload = "loading()"> -->
<body>
<h2>
hi~
</h2>
</body>
</html>

'JavaScript' 카테고리의 다른 글

JavaScript - Global Variable  (0) 2019.09.14
JavaScript - Hoisting  (0) 2019.09.14
JavaScript - Escape character, Operator  (0) 2019.09.14
JavaScript - Datatype  (0) 2019.09.14
What is JavaScript?  (0) 2019.09.14

JavaScript - Escape character, Operator

JavaScript

Escape Character

Escape Character Description
\t Horizontal tab
\n Line break
\' Single quote
\" Double quote
\\ Backslash

Operator

Operator Desc Operator Desc
- minus / divide
+ plus * multiple

example

<!-- 
window.onload = function(){}
1. html 문서에 포함된 모든 콘텐츠가 로드된 후에 실해오디는 함수
2. 동일한 문서에 window.onload 는 단 하나만 존재해야한다.
3. body 태그에도 onload 속성을 지정할 수 있는데 이때 window.onload 속성은 무시된다.
 -->
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
<script type="text/javascript">

	alert(5+3*2);
    alert((5-3)/2);
</script>
</head>
<body>
</body>
</html>​

'JavaScript' 카테고리의 다른 글

JavaScript - Global Variable  (0) 2019.09.14
JavaScript - Hoisting  (0) 2019.09.14
JavaScript - window.onload  (0) 2019.09.14
JavaScript - Datatype  (0) 2019.09.14
What is JavaScript?  (0) 2019.09.14

JavaScript - Datatype

JavaScript

https://www.splessons.com/lesson/javascript-datatypes/

 

Notion : <script type="text/javascript"></script> -> this block is the JavaScript

 

There are 6 Basic Datatypes in JavaScript.

 

1. String : Text

 

2. number : Integer, real number

 

3. boolean : true, false

 

4. function : method

 

5. object : a Data and a Concept includes every function, process related to Data.

 

More Detail for Objects is here
https://www.geeksforgeeks.org/objects-in-javascript/

 

Objects in Javascript - GeeksforGeeks

Objects, in JavaScript, is it’s most important data-type and forms the building blocks for modern JavaScript. These objects are quite different from JavaScript’s primitive data-types(Number,… Read More »

www.geeksforgeeks.org

 

6. undefined : Nothing more Detail go this bookmark

 

https://codeburst.io/javascript-whats-the-difference-between-null-undefined-37793b5bfce6

 

 

alert() : A method for JavaScript 

<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>

<script type="text/javascript">
	var variable;
	var stringVar = "String";
	var numberVar = 123;
	var bolVar = true;
	var functionVar = function(){}; // anonymous function
	var objectVar ={};
	
	alert(typeof stringVar);
	alert(typeof numberVar);
	alert(typeof bolVar);
	alert(typeof functionVar);
	alert(typeof objectVar);
	alert(typeof alpha); //undefined
	alert(typeof variable); //undefined
	
	
</script>

</head>
<body>

</body>
</html>

 

'JavaScript' 카테고리의 다른 글

JavaScript - Global Variable  (0) 2019.09.14
JavaScript - Hoisting  (0) 2019.09.14
JavaScript - window.onload  (0) 2019.09.14
JavaScript - Escape character, Operator  (0) 2019.09.14
What is JavaScript?  (0) 2019.09.14

What is JavaScript?

JavaScript

 

JavaScript is a popular programming language for Web Browser.

 

Until 2010, it cant be used for other purpose except Web Client Development.

 

but After 2010, many things can be programmed with JavaScript like Server, game, SmartPhone App, ETC

 

Let's find out How we can handle with JavaScript. 

'JavaScript' 카테고리의 다른 글

JavaScript - Global Variable  (0) 2019.09.14
JavaScript - Hoisting  (0) 2019.09.14
JavaScript - window.onload  (0) 2019.09.14
JavaScript - Escape character, Operator  (0) 2019.09.14
JavaScript - Datatype  (0) 2019.09.14

How to crawl a webPage by python (BeautifulSoup)

파이썬
from bs4 import BeautifulSoup
import urllib.request

url = 'http://~~'
source_code = urllib.request.urlopen(url).read()
soup = BeautifulSoup(source_code, "html.parser")
for href in soup.find_all('a'):
	print(href.get('href').getText())

it is a code that is collecting all links with tag name 'a' in a page. 

 

before you start a basic crawling, you need to know  few methods, like soup.find() , soup.find_all()

 

find() method needs at least one argument("tag name") to two for crawling.

 

soup.find() method return a soup object list, for example, find_all() method in

 

the sample code on the top in this page is return list of all of 'a' tags  in the url page.

 

and you can get text wiht .getText() method.

 

Because soup.find() and soup.find_all() method return Object class, you can use this object as a iterable variable in

loop statement.

 

url = 'http://'
source_code = urllib.request.urlopen(url).read()
soup = BeautifulSoup(source_code, "html.parser")

soupObject = soup.find_all('div')
for div in soupObject:
	print(div.getText())