-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·84 lines (63 loc) · 1.97 KB
/
main.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import requests
from bs4 import BeautifulSoup
url = "http://tv.niazitv.pk"
# Step 1: Get the HTML
# :- r = content of web site
r = requests.get(url)
htmlContent = r.content
# print(htmlContent)
# Step 2: Parse the Html
soup = BeautifulSoup(htmlContent, 'html.parser')
# print(soup.prettify)
# Step 3: HTML tree travarsel
#
#
# Commonly used types of objects:
# 1: Tag
# 2: Navigable String
# 3: BeautifulSoup object
# 4: Comment
# Get the title
title = soup.title
# print(title)
# Get all the paragraphs
paras = soup.find_all('p')
# print(paras)
# Get all the anchor tags
anchors = soup.find_all('a')
all_links = set()
# Get all the links in the page:
for link in anchors:
if(link.get('href') != '#'):
linkText = "http://tv.niazitv.pk" + link.get('href')
all_links.add(linkText)
# print(linkText)
# print(anchors)
# Get first element of html page
# print(soup.find('p'))
# Get classes of any element of html page
# print(soup.find('p')['class'])
# Find all element with class Lead
# print(soup.find_all('p', class_='lead'))
# Get the text from the Elements i.e tags/soup
# print(soup.find('p').get_text())
# For all text in htm page(soup)
# print(soup.get_text())
navbarSupportedContent = soup.find(id='navbarSupportedContent')
# .contents - A tag's children are available as a list
# .children - A tag's children are available as a generator
# for elem in navbarSupportedContent.contents:
# print(elem)
# for item in navbarSupportedContent.strings:
# print(item)
# for item in navbarSupportedContent.stripped_strings:
# print(item)
# print(navbarSupportedContent.parent)
# for item in navbarSupportedContent.parents:
# print(item.name)
# print(navbarSupportedContent.next_sibling.next_sibling)
# print(navbarSupportedContent.previous_sibling.previous_sibling)
# elem = soup.select('.modal-footer')
# print(elem)
elem = soup.select('#loginModal')[0]
# print(elem)