1
1

00:00:02,800  -->  00:00:04,270
<v Instructor>Let's start off by</v>
2

2

00:00:04,270  -->  00:00:07,223
retrieving the item price from a website.
3

3

00:00:08,060  -->  00:00:08,893
Now, one of the key things that our application
4

4

00:00:08,893  -->  00:00:13,893
is going to do is, it's going to search through online sites
5

5

00:00:14,570  -->  00:00:18,080
that the users have given us and find which items
6

6

00:00:18,080  -->  00:00:20,830
are under the price that the user wants.
7

7

00:00:20,830  -->  00:00:22,650
So for that of course we need to be able
8

8

00:00:22,650  -->  00:00:24,070
to go into a website
9

9

00:00:24,070  -->  00:00:29,070
and a specific item in that website and find their price.
10

10

00:00:29,120  -->  00:00:32,400
So we're going to use a couple of tools to do that.
11

11

00:00:32,400  -->  00:00:35,140
We're going to use the requests module
12

12

00:00:35,140  -->  00:00:37,063
and we're going to use BeautifulSoup.
13

13

00:00:38,260  -->  00:00:39,930
So the first thing we do is to go over
14

14

00:00:39,930  -->  00:00:43,810
to your Pycharm preferences and instal those two things.
15

15

00:00:43,810  -->  00:00:47,320
So I'm going to go over to the project interpreter settings,
16

16

00:00:47,320  -->  00:00:50,460
make sure that you are in the correct interpreter
17

17

00:00:50,460  -->  00:00:53,883
and then press the plus icon and instal BeautifulSoup4.
18

18

00:00:55,935  -->  00:00:58,623
So this is important, it has to be BeautifulSoup4,
19

19

00:00:59,630  -->  00:01:02,820
nothing else, not BeautifulSoup or anything else.
20

20

00:01:02,820  -->  00:01:06,563
Make sure it's BeautifulSoup4 and then press instal.
21

21

00:01:07,590  -->  00:01:09,770
So this is going to instal BeautifulSoup4,
22

22

00:01:09,770  -->  00:01:11,040
this is the one we want
23

23

00:01:11,040  -->  00:01:14,050
and we also need the requests module.
24

24

00:01:14,050  -->  00:01:19,010
Again, make sure it is requests and not any other module
25

25

00:01:19,010  -->  00:01:21,260
that also has the name requests in it.
26

26

00:01:21,260  -->  00:01:23,260
Do make sure that it's just requests,
27

27

00:01:23,260  -->  00:01:25,500
as that is the one we want.
28

28

00:01:25,500  -->  00:01:27,630
And what requests is going to allow
29

29

00:01:27,630  -->  00:01:31,360
is for us to get the website that we're interested in,
30

30

00:01:31,360  -->  00:01:34,000
BeautifulSoup is going to allow us to understand
31

31

00:01:34,000  -->  00:01:37,470
what's in the website so that we can find out the price.
32

32

00:01:37,470  -->  00:01:41,330
So we're going to be be doing that, just press okay.
33

33

00:01:41,330  -->  00:01:45,250
And now we're going to use our app.py to build out
34

34

00:01:45,250  -->  00:01:49,260
something that will find the price in a given website.
35

35

00:01:49,260  -->  00:01:51,300
So I'm gonna delete the flask cap just for now,
36

36

00:01:51,300  -->  00:01:53,160
we're gonna bring it back later on.
37

37

00:01:53,160  -->  00:01:55,990
And the first thing to do is of course to figure out,
38

38

00:01:55,990  -->  00:01:59,790
how we're gonna find the price of a website.
39

39

00:01:59,790  -->  00:02:04,600
If we do import requests, then new can see something like
40

40

00:02:04,600  -->  00:02:08,360
requests.get, and what get is going to do
41

41

00:02:08,360  -->  00:02:12,210
is it's going to retrieve the contents of a website.
42

42

00:02:12,210  -->  00:02:15,710
And the website I'm gonna use in this sample app is
43

43

00:02:15,710  -->  00:02:17,870
this one here, johnlewis.com,
44

44

00:02:17,870  -->  00:02:20,050
this is a department store here in the UK
45

45

00:02:20,050  -->  00:02:23,210
which is quite popular and they have a nice website
46

46

00:02:23,210  -->  00:02:25,840
that we can retrieve item prices for.
47

47

00:02:25,840  -->  00:02:28,440
For this I would recommend that you use
48

48

00:02:28,440  -->  00:02:30,330
the same website as me.
49

49

00:02:30,330  -->  00:02:32,660
That way you can make sure that your code works
50

50

00:02:32,660  -->  00:02:35,260
and after that you can use a different website if you want.
51

51

00:02:35,260  -->  00:02:37,940
But for now, please do stick with the same website as me
52

52

00:02:37,940  -->  00:02:39,700
as some websites won't work,
53

53

00:02:39,700  -->  00:02:41,780
and I'll go into why in a moment.
54

54

00:02:41,780  -->  00:02:46,780
So when we have this requests.get, what we are getting
55

55

00:02:46,800  -->  00:02:50,930
is a response from this website.
56

56

00:02:50,930  -->  00:02:55,930
The response will contain the code that makes up that site.
57

57

00:02:57,500  -->  00:03:01,640
So I'm gonna print response.content just so you can see
58

58

00:03:01,640  -->  00:03:04,860
exactly what goes on when you make one of these requests.
59

59

00:03:04,860  -->  00:03:08,300
I'm gonna press play, and what you can see here
60

60

00:03:08,300  -->  00:03:10,070
is exactly what we got back.
61

61

00:03:10,070  -->  00:03:14,350
Notice that this is a very, very long set of text there,
62

62

00:03:14,350  -->  00:03:15,960
because what we've retrieved
63

63

00:03:15,960  -->  00:03:19,940
is the entire content of the page.
64

64

00:03:19,940  -->  00:03:23,850
And that page in johnlewis.com is an html page
65

65

00:03:23,850  -->  00:03:25,180
that we are retrieving.
66

66

00:03:25,180  -->  00:03:27,170
So this is how you can get that content.
67

67

00:03:27,170  -->  00:03:28,250
Let's go into the next video
68

68

00:03:28,250  -->  00:03:31,440
to understand what that content means.
69

69

00:03:31,440  -->  00:03:32,390
I'll see you there.
