Advertisement
apl-mhd

fiver

Jul 12th, 2019
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.75 KB | None | 0 0
  1. import mechanize
  2.  
  3. #Browser
  4. br = mechanize.Browser()
  5.  
  6. br.set_handle_robots(False)
  7. br.set_handle_refresh(False)
  8. LIST = []
  9. # open link using mechanize
  10. br.open('http://www.ginniemae.gov/Pages/profile.aspx?src=%2fdata_and_reports%2fdisclosure_data%2fPages%2fdatadownload_bulk.aspx')
  11. # html = res.read()
  12. # print(html)
  13.  
  14. #ctl00_ctl30_g_c3bda346_4fcc_41a3_b73c_c3e74349ea9f_ctl00_tbEmailAddress
  15. #ctl00$ctl30$g_c3bda346_4fcc_41a3_b73c_c3e74349ea9f$ctl00$tbAnswer
  16. #ctl00$ctl30$g_c3bda346_4fcc_41a3_b73c_c3e74349ea9f$ctl00$tbAnswer ('new')
  17. # select form which you want to submit.
  18. br.select_form(nr=0)
  19. br.form['ctl00$ctl30$g_c3bda346_4fcc_41a3_b73c_c3e74349ea9f$ctl00$tbEmailAddress'] = 'apeldevac@gmail.com'
  20. br.submit()
  21.  
  22. # select form which you want to submit.
  23. br.select_form(nr=0)
  24. br.form['ctl00$ctl30$g_c3bda346_4fcc_41a3_b73c_c3e74349ea9f$ctl00$tbAnswer'] = 'bmw'
  25. br.submit()
  26.  
  27. # read data from html tree
  28.  
  29. '''
  30. image_response = br.open_novisit('https://bulk.ginniemae.gov/protectedfiledownload.aspx?dlfile=data_bulk/nissues_201906.zip')
  31.  
  32.  
  33. with open('image_out.zip', 'wb') as f:
  34.    f.write(image_response.read())
  35. '''
  36.  
  37.  
  38.  
  39. info = br.response().read().split('<a target="_blank" href="')[1:]
  40.  
  41.  
  42. fileList =[]
  43.  
  44.  
  45. for i in info:
  46.  
  47.     downLoadLink = i.split("\"")[0]
  48.     fileName = downLoadLink.split("/")[-1]
  49.     download = br.open_novisit(downLoadLink)
  50.  
  51.     with open(fileName, 'wb') as f:
  52.         f.write(download.read())
  53.  
  54.     fileList.append(fileName)
  55.  
  56.  
  57. print("list detail : ")
  58. print(fileList)
  59. print("Data fetched successfully.")
  60.  
  61.  
  62.  
  63. '''
  64. print(info[1].split("\""))
  65.  
  66. print(type(info))
  67. print(len(info))
  68. print(type(info[0]))
  69. '''
  70. # iterate data one by one.
  71.  
  72. '''
  73. for i in info:
  74.    x = i.split('>')[2].split('<')[0]
  75. LIST.append(x)
  76.  
  77.  
  78. '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement