-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsession20.py
More file actions
42 lines (32 loc) · 989 Bytes
/
session20.py
File metadata and controls
42 lines (32 loc) · 989 Bytes
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
import requests
from bs4 import BeautifulSoup # External Library for parsing HTML data
url = "https://twitter.com/dna"
response = requests.get(url)
#print(response)
# HTML Parsing : From HTML code extract the desired/ meaningful information
soup = BeautifulSoup(response.text, "html.parser")
#print(soup)
print("Type of soup is:", type(soup))
print("****************************************")
#print(soup)
#print(soup.prettify()) # code will be displayed with indentation
print("Title is:", soup.title.text)
""""
children = soup.children # This api returns all the HTML tags
# Html works as a tree data structure
for child in children:
print(child)
print("-------------------")
"""
""""
pTags = soup.find_all("p")
for tag in pTags:
print(tag)
print("--------------")
"""
#divTags = soup.find_all("div")
divTags = soup.find_all("div",class="js-tweet-text-container")
for tag in divTags:
#print(tag)
print(tag.text)
print("------------------------")