Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import mechanize
- #Browser
- br = mechanize.Browser()
- br.set_handle_robots(False)
- br.set_handle_refresh(False)
- LIST = []
- # open link using mechanize
- br.open('http://www.ginniemae.gov/Pages/profile.aspx?src=%2fdata_and_reports%2fdisclosure_data%2fPages%2fdatadownload_bulk.aspx')
- # html = res.read()
- # print(html)
- #ctl00_ctl30_g_c3bda346_4fcc_41a3_b73c_c3e74349ea9f_ctl00_tbEmailAddress
- #ctl00$ctl30$g_c3bda346_4fcc_41a3_b73c_c3e74349ea9f$ctl00$tbAnswer
- #ctl00$ctl30$g_c3bda346_4fcc_41a3_b73c_c3e74349ea9f$ctl00$tbAnswer ('new')
- # select form which you want to submit.
- br.select_form(nr=0)
- br.form['ctl00$ctl30$g_c3bda346_4fcc_41a3_b73c_c3e74349ea9f$ctl00$tbEmailAddress'] = 'apeldevac@gmail.com'
- br.submit()
- # select form which you want to submit.
- br.select_form(nr=0)
- br.form['ctl00$ctl30$g_c3bda346_4fcc_41a3_b73c_c3e74349ea9f$ctl00$tbAnswer'] = 'bmw'
- br.submit()
- # read data from html tree
- '''
- image_response = br.open_novisit('https://bulk.ginniemae.gov/protectedfiledownload.aspx?dlfile=data_bulk/nissues_201906.zip')
- with open('image_out.zip', 'wb') as f:
- f.write(image_response.read())
- '''
- info = br.response().read().split('<a target="_blank" href="')[1:]
- fileList =[]
- for i in info:
- downLoadLink = i.split("\"")[0]
- fileName = downLoadLink.split("/")[-1]
- download = br.open_novisit(downLoadLink)
- with open(fileName, 'wb') as f:
- f.write(download.read())
- fileList.append(fileName)
- print("list detail : ")
- print(fileList)
- print("Data fetched successfully.")
- '''
- print(info[1].split("\""))
- print(type(info))
- print(len(info))
- print(type(info[0]))
- '''
- # iterate data one by one.
- '''
- for i in info:
- x = i.split('>')[2].split('<')[0]
- LIST.append(x)
- '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement