Last Updated: July 05, 2017
·
280
· NandaKumar Totantila

The programatic way to download Salesforce CSV's

  • Create User Account in force.
  • Select the page you want to crawl.
  • Add header with cookies to your get request.
  • Sample URL : https://my.salesforce.com/?so=0weA0000000Hu5a
  • Save the CSV and use it in your purpose

    def scrapethesalesforce(self baseURL,mydriver):
    baseURL= "https://my.salesforce.com/?so=0weA0000000Hu5a"
    cookies=mydriver.get_cookies()
    cookie=""
    for i in range(0,len(cookies)):
    cookie=cookie+cookies[i]['name']+"="+cookies[i]['value']+";"
    # Add Headers of your Browser
    header={"Host":"my.salesforce.com","User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0",
    "Accept":"text/html,application/xhtml+xml,application/xml,application/x-www-form-urlencoded;q=0.9,/;q=0.8",
    "Accept-Language":"en-US,en;q=0.5",
    "Accept-Encoding":"gzip, deflate",
    "X-Requested-With":"XMLHttpRequest, Portal Project",
    "Content-type": "application/json",
    "Referer":"https://my.salesforce.com/home/home.jsp?sdtd=1",
    "X-Frame-Options":"Deny",
    "Cookie":cookie,
    }
    time.sleep(4)

    r=requests.get(baseURL+'?view=d&snip&export=1&enc=UTF-8&xf=csv',headers=header)
    print r.content
    # Save the Content in the CSV
    f = open('csvfile.csv','w')
    f.write(r.content) #Give your csv text here.
    # Use the CSV for your purpose ex: update to DB