-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathget_bourse_address.py
More file actions
44 lines (32 loc) · 1.05 KB
/
get_bourse_address.py
File metadata and controls
44 lines (32 loc) · 1.05 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
from bs4 import BeautifulSoup
from urllib.request import Request, urlopen
import re
from os.path import basename
import os
# from selenium import webdriver
# driver = webdriver.Chrome()
# driver.get("http://www.tsetmc.com/Loader.aspx?ParTree=111C1417")
#
# html = driver.execute_script("return document.documentElement.innerHTML")
# req = Request("http://www.tsetmc.com/Loader.aspx?ParTree=111C1417")
# html_page = urlopen(req)
fn = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'bourse-page.html')
soup = BeautifulSoup(open(fn), "html.parser")
# soup = BeautifulSoup(html_page, "html.parser")
# print(soup)
links = []
links2 = []
for link in soup.findAll('a'):
# print(link)
links.append(link.get('href'))
for i in range(len(links)):
if i%2:
links2.append(links[i])
# print(links2)
links3 = []
for i in range(len(links2)):
links3.append(links2[i].split("=")[-1])
# print(links3)
f = open("list-bourse-csv.txt", 'w+')
for id in links3:
f.write("http://www.tsetmc.com/tsev2/data/Export-txt.aspx?t=i&a=1&b=0&i={}\n".format(id))