-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathWeb Scraping Basics 1.py
59 lines (30 loc) · 986 Bytes
/
Web Scraping Basics 1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# coding: utf-8
# ## Web Scraping
# > webbrowser Comes with Python and opens a browser to a specific page.<br>
# Requests Downloads files and web pages from the Internet. <br>
# Beautiful Soup Parses HTML, the format that web pages are written in.<br>
# Selenium Launches and controls a web browser. Selenium is able to fill in forms and simulate mouse clicks in this browser.
# In[ ]:
import webbrowser
# In[ ]:
# Opens the given URL
webbrowser.open('https://en.wikipedia.org/wiki/Web_scraping')
# ### Downloading a web page with Request.get() function
# In[ ]:
import requests
res = requests.get('http://www.gutenberg.org/cache/epub/1112/pg1112.txt')
# In[ ]:
type(res)
# In[ ]:
res.status_code == requests.codes.ok
# In[ ]:
print(res.text[:296])
# ### Check for errors
# In[ ]:
import requests
res = requests.get('https://marvelapp.com/asdf')
try:
res.raise_for_status()
except Exception as exc:
print('There was a problem: %s' % (exc))
# In[ ]: