Question

Can FME download the css file from a website?

  • 19 March 2019
  • 6 replies
  • 5 views

http://m.dianping.com/shop/22242399

I tired the HTTPcaller to download the .css file from DianPing. It returns an error.

 


6 replies

Userlevel 1
Badge +22

FME should be able to retrieve any resource that can be accessed via HTTP using the HttpCaller. But without the actual url/uri you use to retrieve the CSS, it's rather impossible to comment further. You may also need to set up some specific header information in HttpCaller, e.g. some login or ticket information. In your case maybe also some transfer-encoding information.

FME should be able to retrieve any resource that can be accessed via HTTP using the HttpCaller. But without the actual url/uri you use to retrieve the CSS, it's rather impossible to comment further. You may also need to set up some specific header information in HttpCaller, e.g. some login or ticket information. In your case maybe also some transfer-encoding information.

http://s3plus.meituan.net/v1/mss_0a06a471f9514fc79c981b5466f56b91/svgtextcss/dc63fe513c002f0f6dde345e4bbb7bdf.css

This is the url. I tried to set up the header information in httpcaller, but it doesn't work.

Userlevel 4

Unfortunately the HTTPCaller seems to dislike raw responses without any content-type headers, such as is the case when you try to read the CSS from this server.

However, you can use a small Python script instead:

import fmeobjects
try:
    import urllib2 as urlreq  # Python 2
except:
    import urllib.request as urlreq  # Python 3
    
def raw_get(feature):
    req = urlreq.Request("http://s3plus.meituan.net/v1/mss_0a06a471f9514fc79c981b5466f56b91/svgtextcss/dc63fe513c002f0f6dde345e4bbb7bdf.css")
    contents = urlreq.urlopen(req).read()
    feature.setAttribute('css_contents', contents.decode("utf-8"))

The output feature will have a new attribute css_contents containing the raw text returned by the URL.

Unfortunately the HTTPCaller seems to dislike raw responses without any content-type headers, such as is the case when you try to read the CSS from this server.

However, you can use a small Python script instead:

import fmeobjects
try:
    import urllib2 as urlreq  # Python 2
except:
    import urllib.request as urlreq  # Python 3
    
def raw_get(feature):
    req = urlreq.Request("http://s3plus.meituan.net/v1/mss_0a06a471f9514fc79c981b5466f56b91/svgtextcss/dc63fe513c002f0f6dde345e4bbb7bdf.css")
    contents = urlreq.urlopen(req).read()
    feature.setAttribute('css_contents', contents.decode("utf-8"))

The output feature will have a new attribute css_contents containing the raw text returned by the URL.

Wow! I'll have a try, thanks very much.

Userlevel 3
Badge +18

Unfortunately the HTTPCaller seems to dislike raw responses without any content-type headers, such as is the case when you try to read the CSS from this server.

However, you can use a small Python script instead:

import fmeobjects
try:
    import urllib2 as urlreq  # Python 2
except:
    import urllib.request as urlreq  # Python 3
    
def raw_get(feature):
    req = urlreq.Request("http://s3plus.meituan.net/v1/mss_0a06a471f9514fc79c981b5466f56b91/svgtextcss/dc63fe513c002f0f6dde345e4bbb7bdf.css")
    contents = urlreq.urlopen(req).read()
    feature.setAttribute('css_contents', contents.decode("utf-8"))

The output feature will have a new attribute css_contents containing the raw text returned by the URL.

Could we call it a bug that FME is not able to accept raw content. I tried different settings like tread as binary, write to file, but FME does not accept.

I think that if I say the data is binary FME must accept my settings.

 

 

Userlevel 4

Could we call it a bug that FME is not able to accept raw content. I tried different settings like tread as binary, write to file, but FME does not accept.

I think that if I say the data is binary FME must accept my settings.

 

 

Yes, that would be my opinion as well.

Reply