-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.py
More file actions
94 lines (50 loc) · 2.37 KB
/
Copy pathMain.py
File metadata and controls
94 lines (50 loc) · 2.37 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
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
85
86
87
88
89
90
91
92
93
94
import requests
from bs4 import BeautifulSoup
import sublink
# URL of the FOMC statements page
url = 'https://www.federalreserve.gov/newsevents/pressreleases.htm'
primarylink = "https://www.federalreserve.gov"
response = requests.get(url)
response.raise_for_status() # Check for request errors
# Parse the page content
soup = BeautifulSoup(response.content, 'html.parser')
#search_text = "Federal Reserve issues FOMC statement"
div = soup.find('div', id='article')
statements = div.find_all('a', href=True) # Adjust as needed
# Example to print all statement links
for link in statements[0:len(statements)-6]:
link_text = link.get_text(strip=True)
#print(link_text, link['href'])
secondary_link = link['href']
response = requests.get(primarylink+secondary_link)
response.raise_for_status() # Check for request errors
soup = BeautifulSoup(response.content, 'html.parser')
div = soup.find('div', id='content')
statements2 = div.find_all('a', href=True) # Adjust as needed
for link in statements2:
link_text = link.get_text(strip=True)
#print(link_text)
search_text = "Federal Reserve issues FOMC statement"
if search_text in link_text:
href = link['href']
print(f'Found link with text "{search_text}": {href}')
found = True
sublink.fomcspeechpage(primarylink,href)
for link in statements[len(statements)-7:len(statements)]:
link_text = link.get_text(strip=True)
#print(link_text, link['href'])
secondary_link = link['href']
response = requests.get(primarylink+secondary_link)
response.raise_for_status() # Check for request errors
soup = BeautifulSoup(response.content, 'html.parser')
div = soup.find('div', id='content')
statements2 = div.find_all('a', href=True) # Adjust as needed
for link in statements2:
link_text = link.get_text(strip=True)
#print(link_text)
search_text2 = "FOMC statement"
if search_text2 in link_text:
href = link['href']
print(f'Found link with text "{search_text2}": {href}')
found = True
sublink.fomcspeechpage(primarylink, href)