-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
60 lines (43 loc) · 1.17 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
import requests
from bs4 import BeautifulSoup
url="https://indianexpress.com/"
r=requests.get(url)
htmlContent=r.content
#print(htmlContent)
soup=BeautifulSoup(htmlContent,'html.parser')
#print(soup.prettify)
#title=soup.title
#print(type(soup))
#print(type(title))
#print(type(title.string))
#paras=soup.find_all('p')
#print(paras)
#print(soup.find('p'))
#print(soup.find('p')['class'])
#no class in this websites
#print(soup.find('p').get_text())
#print(soup.get_text())
#markup="<p><!-- this is a comment --></p>"
#soup2=BeautifulSoup(markup)
#print((soup2.p.string))
#exit()
#anchors=soup.find_all('a')
#print(anchors)
#all_links=set()
#for link in anchors:
#if(link.get('href') !='#'):
#linkText="https://indianexpress.com/" +link.get('href')
#all_links.add(link)
#print(linkText)
# Check if the request was successful
if r.status_code == 200:
# Step 1: Extract headlines
headlines = soup.find_all('h3')
# Step 2: Print the extracted headlines
for headline in headlines:
print(headline.get_text())
else:
print("Failed to retrieve the web page")
# CSS Selector
#elem=soup.select('evnav_login_ham')
#print(elem)