-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1_srcCode_webpage.py
More file actions
32 lines (24 loc) · 1.07 KB
/
1_srcCode_webpage.py
File metadata and controls
32 lines (24 loc) · 1.07 KB
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
import requests
import bs4
# The commented part of the code prints the source code of the requested webpage
print()
result = requests.get("http://www.example.com")
print("Type of value returned by requests.get() -->",type(result))
# print("\n ______________Source Code of the webpage________________________\n")
# print(result.text)
print("\n\n")
soup = bs4.BeautifulSoup(result.text,"lxml")
# print("SOUP(Source Code of the webpage) ---\n", soup)
print("soup.select('title') ---->",soup.select('title'))
print("soup.select('h1') ---->",soup.select('h1'))
print()
print("soup.select('title')[0] ---->",soup.select('title')[0])
print("soup.select('title')[0].getText() ---->",soup.select('title')[0].getText())
print()
site_paragraphs = soup.select("p")
print("type(site_paragraphs) --->",type(site_paragraphs),"\n\n")
print("site_paragraphs[0] ---> ",site_paragraphs[0])
print("site_paragraphs[1] ---> ",site_paragraphs[1])
print()
print("site_paragraphs[0].getText() ---> ",site_paragraphs[0].getText())
print("site_paragraphs[1].getText() ---> ",site_paragraphs[1].getText())