---
# System prepended metadata

title: '5.Friday, 19-07-2019, Request & BeautifulSoup. Scrape all products on tiki.vn'

---

# 5.Friday, 19-07-2019, Request & BeautifulSoup. Scrape all products on tiki.vn

### Request
>This library is used to get HTML code from a website
>
```
import requests

res = requests.get('https://tiki.vn')
```

### Try - Except
>When we have an error during executing code, it will write a notification instead of stopping our code.
```
try:
  res = requests.get('http://not_exists_page')
except Exception as err:
  print('There was a problem: {}'.format(err))
```

### BeautifulSoup
>Format HTML code
>
```
from bs4 import BeautifulSoup

res = requests.get('http://tiki.vn')
soup = BeautifulSoup(res.text)
```

* Find_all
>To find a TAG in HTML code
>Ex: Take all a TAG with class = 'MenuItem__MenuLink-tii3xq-1 efuIbv' in a HTML code
```
s.find_all('a', class_='MenuItem__MenuLink-tii3xq-1 efuIbv')
```
* Find
>Find a SUB TAG
```
find('span', class_='text').text
```
* Get
>Get an element from a TAG
```
get('href')
```

```
for i in s.find_all('a', class_='MenuItem__MenuLink-tii3xq-1 efuIbv'):
    url = i.get('href')
    category = i.find('span', class_='text').text
    categ_list.append((category, url))
```

* Pop()
> Take the last element of a list then remove it