设为首页收藏本站

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1049|回复: 3

craigslist Bulk Posting Interface

[复制链接]
发表于 2014-2-2 04:47:05 | 显示全部楼层 |阅读模式
Overview:               craigslist provides a bulk posting interface for easy submission of multiple new posts in a single request to our server.  This document describes that interface and how it is used.   
    New postings are submitted to the bulk interface in RSS format with additional craigslist-specific elements via HTTPS POST.  craigslist returns another RSS document detailing which postings are valid or which have been posted.   
    A description of the protocol, RSS submission and response formats, and a reference of acceptable values is below.

     Protocol:    Request:      Submitting a request to post or validate postings is done by:        

  • establishing an HTTPS connection to craigslist at one of these URLs:


              
    • https://post.craigslist.org/bulk-rss/validate - Submit RSS to this URL to be validated.
    • https://post.craigslist.org/bulk-rss/post - Submit RSS to this URL to be posted.
  • sending an HTTP request with a Content-Type of "application/x-www-form-urlencoded" and containing RSS content in the correct format
  • waiting for a response.
            See the code sample in this document for an example bulk post client.   
Response:    Possible HTTP status values:   


         
  • 415 Unsupported Media Type -
            


               
    • "Failed to parse RSS" - This error occurs when the posting submission RSS document is not well-formed, or if the parser encounters an error processing the format of the RSS.  A detailed parse failure message should accompany this error.
               
  • 403 Forbidden -
            


               
    • "Must supply username" - A username was not supplied in the <cl:auth> element.
    • "Must supply password" - A password was not supplied in the <cl:auth> element.
    • "AccountID required" - An accountID was not supplied in the <cl:auth> element.
    • "Invalid username/password" - Username and/or password supplied in RSS submission are not known or invalid.
    • "This user account is not granted bulk post access" - The user account supplied is not authorized to use the bulk posting interface.  Please contact craigslist with authorization requests.
    • "User is not a buyer for account" - The user account supplied is not indicated as an authorized buyer for the accountID supplied.
               
  • 200 OK -         Content of response will be RSS document in posting response format      

    Posting Submission Format:    Below is a sample RSS bulk posting submission containing two NYC housing postings.          A submission consists of a <channel> element containing a list of    postings to be processed (within <items> element), and a    <cl:auth> element containing authentication credentials for the user    submitting the postings.  The <items> element should contain    <rdf:li> elements, each having an attribute, rdf:resource=, whose value is an arbitrary user-supplied string identifying each posting.  These identifiers need only be unique within the RSS document.   
    Additionally, there is an <item> element for every posting submitted,    containing various subelements defining the post content.  The about=    attribute of this element should contain a value that matches one of the    rdf:resource= attributes in an <rdf:li> element.  A description of the various elements allowed within each <item> is below this example.

  1. <?xml version="1.0"?>

  2. <rdf:RDF xmlns="http://purl.org/rss/1.0/"
  3.          xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  4.          xmlns:cl="http://www.craigslist.org/about/cl-bulk-ns/1.0">

  5.   <channel>
  6.     <items>
  7.       <rdf:li rdf:resource="NYCBrokerHousingSample1"/>
  8.       <rdf:li rdf:resource="NYCBrokerHousingSample2"/>
  9.     </items>

  10.     <cl:auth username="listuser@bogus.com"
  11.              password="p0stp@rty"
  12.              accountID="14"/>
  13.   </channel>

  14.   <item rdf:about="NYCBrokerHousingSample1">
  15.     <cl:category>fee</cl:category>
  16.     <cl:area>nyc</cl:area>
  17.     <cl:subarea>mnh</cl:subarea>
  18.     <cl:neighborhood>Upper West Side</cl:neighborhood>
  19.     <cl:housingInfo price="1450"
  20.                     bedrooms="0"
  21.                     sqft="600"/>
  22.     <cl:replyEmail privacy="C">bulkuser@bulkposterz.net</cl:replyEmail>
  23.     <cl:brokerInfo companyName="Joe Sample and Associates"
  24.                    feeDisclosure="fee disclosure here" />
  25.     <title>Spacious Sunny Studio in Upper West Side</title>
  26.     <description><![CDATA[
  27.       posting body here
  28.     ]]></description>
  29.   </item>

  30.   <item rdf:about="NYCBrokerHousingSample2">
  31.     <cl:category>fee</cl:category>
  32.     <cl:area>nyc</cl:area>
  33.     <cl:subarea>mnh</cl:subarea>
  34.     <cl:neighborhood>Chelsea</cl:neighborhood>
  35.     <cl:housingInfo price="2175"
  36.                     bedrooms="1"
  37.                     sqft="850"
  38.                     catsOK="1"/>
  39.     <cl:mapLocation city="New York"
  40.                     state="NY"
  41.                     crossStreet1="23rd Street"
  42.                     crossStreet2="9th Avenue"
  43.                     latitude="40.746492"
  44.                     longitude="-74.001326"
  45.     />
  46.     <cl:replyEmail privacy="C"
  47.                    otherContactInfo="212.555.1212">
  48.       bulkuser@bulkposterz.net
  49.     </cl:replyEmail>
  50.     <cl:brokerInfo companyName="Joe Sample and Associates"
  51.                    feeDisclosure="fee disclosure here" />
  52.     <title>1BR Charmer in Chelsea</title>
  53.     <description><![CDATA[
  54.       posting body goes here
  55.     ]]></description>
  56.     <cl:PONumber>Purchase Order 094122</cl:PONumber>
  57.     <cl:image position="1">/9j/4AAQSkZJRgABAQEASABIAAD/4QCARXhpZgAATU0AKgAAAAgABQESAAMAAAABAAEAAAEaAAUA
  58. AAABAAAASgEbAAUAAAABAAAAUgEoAAMAAAABAAIAAIdpAAQAAAABAAAAWgAAAAAAAABIAAAAAQAA
  59. AEgAAAABAAKgAgAEAAAAAQAAABCgAwAEAAAAAQAAABAAAAAA/9sAQwABAQEBAQEBAQEBAQEBAQEB
  60. AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB/9sAQwEBAQEB
  61. AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB
  62. AQEB/8AAEQgAEAAQAwERAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//E
  63. ALUQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJ
  64. ChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeI
  65. iYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6Onq
  66. 8fLz9PX29/j5+v/EAB8BAAMBAQEBAQEBAQEAAAAAAAABAgMEBQYHCAkKC//EALURAAIBAgQEAwQH
  67. BQQEAAECdwABAgMRBAUhMQYSQVEHYXETIjKBCBRCkaGxwQkjM1LwFWJy0QoWJDThJfEXGBkaJico
  68. KSo1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoKDhIWGh4iJipKTlJWWl5iZ
  69. mqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uLj5OXm5+jp6vLz9PX29/j5+v/a
  70. AAwDAQACEQMRAD8A+4/jzpGrf8FNf2Kv27P+ClX7T/x08Z+Dv2ZvBPhL9orw/wDsDfs4eHvHUvgD
  71. 4Y3V58NrDxH4Q+H3xN+KMVvPbN8Q/iL48+Klja6VoXhu8nb/AInQn0C2k1TQ9T0nQLL+0eH61Hwt
  72. 444A8MOFchwWN4px+M4bxHiFxNiMAswzWMMzqYbG5jlWVOcZrLsty/Kak6uIxUIq1C2Il7LEUq2I
  73. n/QeWVIcF8R8McHZJlmHxGdYnEZPV4pzerhVisbGOMnSxGLweCbUvqmEwuBnKdWtFL93aq+SpCdW
  74. TPgHpOr/APBMz9in9hT/AIKV/swfHTxn4x/Zm8beFP2ePD37fP7OHiHx1L4/+GNrefEey8PeD/iB
  75. 8TfhdFcT3LfD34i+A/ilfXWl674bs51zrLQaDcSaXoem6toF6+IatHxS454+8MOKshwOC4pwOM4k
  76. xPh7xNhsAsvzSdPLKmJxuXZXmrgorMstzDKYRq0MTOL/AHPNiIqriKtHEQeaVKfGnEfE/B2dZZh8
  77. PnWGr5vV4WzijhfquNlHByq4jC4PGtcv1vCYrBRU6VaSf7vmqrnqThVj8N/ttfspePP2M9M+NP7L
  78. 37Yl/wDHvXP2C/hX8Of2nPHX/BNw/C/wdeap8DtV+PHxWtvGuvfDlP2hPFvhu6TWNE8W/D7xH4lF
  79. lo2k+ILCTTZtXW+1iC50zwFqOuJ4u+84F4ty/jarkfFfBdPh+h4g5tmXC2A8Tf7VxsaWfUeH8ong
  80. cPmT4cwmKi6FfB5jhsM6leth6ntVRcKDjVzCnQ+p/S8N55heIp5bnfD0cqp8U47GZLheMPruIjDM
  81. 4ZXgZYeljHlOHrJ06lDF0aLlUqUpe0UHCm1PFQpOg79ib9lPx1+2bpHwU/Zd/Y6vfj5oX7B/xU+H
  82. X7M3jr/gpM3xQ8H3emfAzTfjt8KYPBevfEJf2evFviS6fWda8X/EHxD4baw1zSPD+nx6XFq50/Wp
  83. rrU/Aen6LH4ROOuLcBwTWz3ivjSHD1fxAynMuKMB4YrKsbGrn1XIM3njsPlz4jweFgqFHB5bhsT7
  84. ShWxFV1XR9pQUKWYVKzxhxJnmG4dqZnnfEMcrqcUYHF5zhuD/qWIjPM55ZjpYmlhP7WoUV7OnQwl
  85. KtzUqlWXO6fPTShiZVHiP//Z
  86.     </cl:image>
  87.   </item>
  88. </rdf:RDF>
复制代码

 楼主| 发表于 2014-2-2 04:55:54 | 显示全部楼层
Inside <channel> Element: Note:  time-related attributes specified as "integer" will  often be  POSIX timestamps; i.e. seconds since 1 January 1970 UTC (except when they aren't). required:      

  • <cl:auth> - Authentication information for this submission.              
    Attributes:

    • username - email address used to log into craigslist account / authenticate.
    • password - craigslist user password.
    • accountID - A craigslist account number with sufficient  block credit (or an invoiced account), where the username supplied is an authorized buyer for this accountID.
          
    Inside <item> Elements: required:      

  • <title> - The title of the post.
  • <description> - The content (body) of the post.
  • <cl:category> - The category where this will be posted.  Contents should be a valid category abbreviation.
  • <cl:area> - The area (city) where this will be posted. Contents should be a valid area abbreviation.
  • <cl:replyEmail> - Reply email address for this post.              
    Attributes:

    • privacy - How reply email should be displayed on the post.
      (A=don't show any email address, C=use anonymous craigslist email address, P=publicly show the replyEmail address)
    • outsideContactOK - (0 or 1) If set to 0, will add text to bottom of post: it's NOT ok to contact this poster with services or other commercial interests.
    • otherContactInfo - Any alternate contact info text.
          
      optional:      
  • <cl:image position="[0-23]">  - Base 64 (rfc 2045) encoded jpeg image.  The optional "position" attribute determines the order in which              the images will be layed out on the posting page. The image at position 0 will be featured on search pages, etc. so put the best one there.              You may specify up to 24 images.           
  • <cl:subarea> - Subarea where this will be posted.  Ad will be posted under this subarea as well as "all areas".  Contents should be a valid subarea abbreviation.
  • <cl:neighborhood> - The name of the neighborhood that this post applies to.  (free-form text)
  • <cl:price> - Advertised price. (numeric value)
  • <cl:mapLocation> - Information for creating map links.            
    Attributes:

    • city - City name in text, such as "New York"
    • state - State postal abbreviation, such as "NY"
    • crossStreet1 - Cross street name
    • crossStreet2 - Other cross street name
    • latitude - Latitude of item (signed floating point number).
    • longitude - Longitude of item (signed floating point number). See latitude.
    Note:  The latitude and longitude attributes determine the position of the pin for the post in the craigsist map view.
                     You must specify them for your post to appear in map views.              
                   
  • <clONumber> - A purchase order number or internal tracking number for your own record-keeping purposes.  (free-form text)
  • <cl:housingInfo> - Housing info fields.         
    Attributes:

    • price - Advertised price. (numeric value)
    • bedrooms - Number of bedrooms. (integer, 0=studio)
    • sqft - Surface area of the space.
    • catsOK - (0 or 1) Add Cats are OK notice to bottom of post.
    • dogsOK - (0 or 1) Add Dogs are OK notice to bottom of post.
  • <cl:brokerInfo> - housing broker information         
    Attributes:

    • companyName - Broker company name.
    • feeDisclosure - Broker fee disclosure.
  • <cl:jobInfo> - Jobs info fields.         
    Attributes:

    • compensation - Compensation rate. (numeric value)
    • telecommuting - (0 or 1) Indicates telcommuting job.
    • partTime - (0 or 1) Indicates part-time job.
    • contract - (0 or 1) Indicates contract job.
    • nonprofit - (0 or 1) Indicates non-profit employer.
    • internship - (0 or 1) Indicates internship job.
    • disability - (0 or 1) Indicates OK to repost to job developers for persons with disabilities
    • recruitersOK - (0 or 1) Add Recruiters OK notice to bottom of post.
    • phoneCallsOK - (0 or 1) Add Phone calls OK notice to bottom of post.
    • okToContact - (0 or 1) Add OK to contact notice to bottom of post.
    • okToRepost - (0 or 1) Add OK to repost notice to bottom of post.
  • <cl:auto_basics> -
    Attributes:
    • auto_make_model -  string
    • auto_miles -  integer
    • auto_trans_auto - ("0" or "1")
    • auto_trans_manual - ("0" or "1")
    • auto_vin -  string
    • auto_year - ("1900", "1901", "1902", "1903", "1904", "1905", "1906", "1907", "1908", "1909", "1910", "1911", "1912", "1913", "1914", "1915", "1916", "1917", "1918", "1919", "1920", "1921", "1922", "1923", "1924", "1925", "1926", "1927", "1928", "1929", "1930", "1931", "1932", "1933", "1934", "1935", "1936", "1937", "1938", "1939", "1940", "1941", "1942", "1943", "1944", "1945", "1946", "1947", "1948", "1949", "1950", "1951", "1952", "1953", "1954", "1955", "1956", "1957", "1958", "1959", "1960", "1961", "1962", "1963", "1964", "1965", "1966", "1967", "1968", "1969", "1970", "1971", "1972", "1973", "1974", "1975", "1976", "1977", "1978", "1979", "1980", "1981", "1982", "1983", "1984", "1985", "1986", "1987", "1988", "1989", "1990", "1991", "1992", "1993", "1994", "1995", "1996", "1997", "1998", "1999", "2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008", "2009", "2010", "2011", "2012", "2013", "2014" or "2015")
  • <cl:generic> -
    Attributes:
    • contact_method - ("email only", "email or phone", "email or text", "phone only", "phone, text, or email", "text only" or "text or phone")
    • contact_name -  string
    • contact_ok - ("0" or "1")
    • contact_phone -  string
    • contact_phone_ok - ("0" or "1")
    • contact_text_ok - ("0" or "1")
    • fee_disclosure -  string
    • has_license - ("0" or "1")
    • license_info -  string
    • phonecalls_ok - ("0" or "1")
    • repost_ok - ("0" or "1")
    • see_my_other - ("0" or "1")
  • <cl:housing_basics> -
    Attributes:
    • bathrooms - ("1", "1.5", "2", "2.5", "3", "3.5", "4", "4.5", "5", "5.5", "6", "6.5", "7", "7.5", "8", "8.5", "9+", "shared" or "split")
    • housing_type - ("apartment", "assisted living", "condo", "cottage/cabin", "duplex", "flat", "house", "in-law", "land", "loft", "manufactured" or "townhouse")
    • is_furnished - ("0" or "1")
    • laundry - ("laundry in bldg", "laundry on site", "w/d hookups" or "w/d in unit")
    • no_smoking - ("0" or "1")
    • parking - ("attached garage", "carport", "detached garage", "off-street parking", "street parking" or "valet parking")
    • wheelchaccess - ("0" or "1")
  • <cl:housing_terms> -
    Attributes:
    • rent_period - ("daily", "monthly", "weekly" or "yearly")
  • <cl:job_basics> -
    Attributes:
    • company_name -  string
    • disability_ok - ("0" or "1")
    • is_contract - ("0" or "1")
    • is_forpay - ("0" or "1")
    • is_internship - ("0" or "1")
    • is_nonprofit - ("0" or "1")
    • is_parttime - ("0" or "1")
    • is_telecommuting - ("0" or "1")
    • is_volunteer - ("0" or "1")
    • recruiters_ok - ("0" or "1")
    • remuneration -  string

Posting Response Format:    Below are some examples of an RSS response for validation and posting, as well as a description.

Validation:
  1. <rdf:RDF xmlns="http://purl.org/rss/1.0/"
  2.          xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  3.          xmlns:cl="http://www.craigslist.org/about/cl-bulk-ns/1.0">
  4.   <channel>
  5.     <items>
  6.       <rdf:Seq>
  7.         <rdf:li rdf:resource="NYCBrokerHousingSample1"/>
  8.         <rdf:li rdf:resource="NYCBrokerHousingSample2"/>
  9.       </rdf:Seq>
  10.     </items>
  11.   </channel>
  12.   <item rdf:about="NYCBrokerHousingSample1">
  13.     <cl:postedStatus>VALID</cl:postedStatus>
  14.     <cl:postedExplanation>This posting seems to be valid.</cl:postedExplanation>
  15.     <cl:previewHTML><![CDATA[
  16.       HTML preview of posting will appear here.
  17.     ]]></cl:previewHTML>
  18.   </item>
  19.   <item rdf:about="NYCBrokerHousingSample2">
  20.     <cl:postedStatus>VALID</cl:postedStatus>
  21.     <cl:postedExplanation>This posting seems to be valid.</cl:postedExplanation>
  22.     <cl:previewHTML><![CDATA[
  23.       HTML preview of posting will appear here.
  24.     ]]></cl:previewHTML>
  25.   </item>

  26. </rdf:RDF>
复制代码
Sample RSS Validation Response
 楼主| 发表于 2014-2-2 04:57:21 | 显示全部楼层

Posting:
  1. <rdf:RDF xmlns="http://purl.org/rss/1.0/"
  2.          xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  3.          xmlns:cl="http://www.craigslist.org/about/cl-bulk-ns/1.0">
  4.   <channel>
  5.     <items>
  6.       <rdf:Seq>
  7.         <rdf:li rdf:resource="NYCBrokerHousingSample1"/>
  8.         <rdf:li rdf:resource="NYCBrokerHousingSample2"/>
  9.       </rdf:Seq>
  10.     </items>
  11.   </channel>
  12.   <item rdf:about="NYCBrokerHousingSample1">
  13.     <cl:postedStatus>POSTED</cl:postedStatus>
  14.     <cl:postedExplanation>Successfully enqueued posting.</cl:postedExplanation>
  15.     <cl:postingID>159144091</cl:postingID>
  16.     <cl:postingManageURL>https://post.craigslist.org/manage/159144091/to6s1
  17.     </cl:postingManageURL>
  18.     <cl:previewHTML><![CDATA[
  19.       HTML preview of posting will appear here.
  20.     ]]></cl:previewHTML>
  21.   </item>
  22.   <item rdf:about="NYCBrokerHousingSample2">
  23.     <cl:postedStatus>POSTED</cl:postedStatus>
  24.     <cl:postedExplanation>Successfully enqueued posting.</cl:postedExplanation>
  25.     <cl:postingID>159144092</cl:postingID>
  26.     <cl:postingManageURL>https://post.craigslist.org/manage/159144092/b0n65
  27.     </cl:postingManageURL>
  28.     <cl:previewHTML><![CDATA[
  29.       HTML preview of posting will appear here.
  30.     ]]></cl:previewHTML>
  31.   </item>

  32. </rdf:RDF>
复制代码


Sample RSS Posting Response
<item> Elements:

    <cl:postedStatus> - Status of processing this posting. Possible values are VALID, NOT_VALID, INSUFFICIENT_BLOCKS, POSTED, and FAILED. VALID appears only in validation mode and if your RSS document is valid. NOT_VALID appears in post and validate modes and will be accompanied by message in <cl:postedExplanation> detailing where the validation failed. INSUFFICIENT_BLOCKS is reported when the accountID supplied does not have enough remaining blocks to create a posting in the city/category and is not an invoiced account, more blocks must be purchased before the posting is processed. POSTED indicates that the posting was successfully accepted. FAILED indicates an unexpected error at post time.
    <cl:postedExplanation> - Human-readable status of processing this posting. If there is an error in validation, error details will appear in this element.
    <cl:previewHTML> - HTML preview of submitted posting.
    <cl:warning> - Warnings related to this post; typically, these will be non-fatal xml parsing issues. This tag will be specified once per warning.
    <cl:postingID> - In post mode, this element will contain the craigslist ID of the newly created posting.
    <cl:postingManageURL> - In post mode, this element will contain a URL that can be used to edit or delete the new posting.

See the sample XSLT in this document for a possible way to process a response.

Note: If you submit a posting item with the same rdf:about as an existing posting item, the existing posting item will not be updated. Presently the only way to alter the content of a posting is via URL specificed in the cl:postingManageURL element.
 楼主| 发表于 2014-2-2 05:01:35 | 显示全部楼层

Sample Bulk Post Client:

    This example bulk posting client script is written in perl5 and requires the LWP perl module.  It processes commandline options, reads an RSS file from disk, then submits it to craigslist for either verification or posting.  It returns the reply RSS to STDOUT unless -o option is specified.
  1. #!/usr/bin/perl
  2. use LWP;
  3. use LWP::UserAgent;
  4. use Getopt::Std;
  5. use strict;

  6. use constant BASE_URL => 'https://post.craigslist.org/bulk-rss';

  7. # process options
  8. my $opts = {};
  9. getopts('o:f:p', $opts);
  10. my $post     = $opts->{'p'};
  11. my $filename = $opts->{'f'};
  12. my $outfile  = $opts->{'o'};
  13. unless($filename) {
  14.   print "usage: $0 [-p] [-o outfile] -f filename\n".
  15.         "       options:\n".
  16.         "       -f  -  the name of the RSS file to submit (required)\n".
  17.         "       -p  -  actually post (otherwise just validate)\n".
  18.         "       -o  -  output filename (otherwise results sent to STDOUT)\n\n";
  19.   exit(0);
  20. }

  21. # open file
  22. my $content = undef;
  23. open(CFH, "<$filename") || die "can't open $filename for read: $!";
  24. { local $/ = undef; $content = <CFH>; }
  25. close(CFH);

  26. # prepare request
  27. my $ua = LWP::UserAgent->new();
  28. $ua->agent('SampleBulkPostClient/0.1');
  29. my $post_url = BASE_URL .'/'. ($post? 'post': 'validate');
  30. my $req = HTTP::Request->new( POST => $post_url );
  31. $req->content_type('application/x-www-form-urlencoded');
  32. $req->content($content);

  33. # issue request
  34. my $res = $ua->request($req);

  35. # print result
  36. if($res->is_success()) {
  37.   if($outfile) {
  38.     open(OFH,">$outfile") || die "can't open $outfile for write: $!";
  39.     print OFH $res->content();
  40.     close OFH;
  41.   }
  42.   else {
  43.     print $res->content()."\n";
  44.   }
  45. }
  46. else {
  47.   print "request failed:\n".   
  48.         $res->status_line()."\n".$res->content()."\n";
  49. }
复制代码
Sample Perl Bulk Posting Client Script
   
Sample XSLT for transforming from the        Posting Response Format to HTML    Here's an example XSLT stylesheet for transforming a posting response.  This example converts a posting response to HTML.

  1. <xsl:stylesheet version = '1.0'
  2.      xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
  3.      extension-element-prefixes="cl rdf"
  4.      xmlns:rss="http://purl.org/rss/1.0/"
  5.      xmlns:cl="http://www.craigslist.org/about/cl-bulk-ns/1.0"
  6.      xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">

  7.   <xsl:template match="/">
  8.     <html>
  9.       <head><title>Bulk posting results</title>
  10.       <style type="text/css">
  11.         tr.error { color : red; }
  12.       </style>
  13.       </head>
  14.       <body>
  15.         <xsl:apply-templates select="rdf:RDF"/>
  16.       </body>
  17.     </html>
  18.   </xsl:template>

  19.   <xsl:template match="rdf:RDF">
  20.     <h3> Bulk posting results: </h3>
  21.     <xsl:apply-templates select="rss:channel"/>
  22.     <table border="1">
  23.     <thead>
  24.       <tr> <td>Item</td><td>Status</td><td>Explanation</td><td>ID</td><td>Warnings</td> </tr>
  25.     </thead>
  26.     <xsl:apply-templates select="rss:item">
  27.       <xsl:sort select="@rdf:about"/>
  28.     </xsl:apply-templates>
  29.     </table>
  30.   </xsl:template>

  31.   <xsl:template match="rss:channel">
  32.     <xsl:apply-templates select="rss:items"/>
  33.   </xsl:template>

  34.   <xsl:template match="rss:item">
  35.     <xsl:variable name='status' select="cl:postedStatus"/>
  36.     <xsl:variable name='rowclass'>
  37.       <xsl:choose>
  38.         <xsl:when test="$status = 'POSTED' or $status = 'VALID'">
  39.           <xsl:text>valid</xsl:text>
  40.         </xsl:when>
  41.         <xsl:otherwise>
  42.           <xsl:text>error</xsl:text>
  43.         </xsl:otherwise>
  44.       </xsl:choose>
  45.     </xsl:variable>
  46.     <tr class="{$rowclass}">
  47.       <td> <xsl:value-of select="@rdf:about"/> </td>
  48.       <td> <xsl:value-of select="$status"/> </td>
  49.       <td> <xsl:value-of select="cl:postedExplanation"/> </td>
  50.       <td>
  51.         <a href="{cl:postingManageURL}">
  52.           <xsl:value-of select="cl:postingID"/>
  53.         </a>
  54.       </td>
  55.       <td>
  56.         <ul>
  57.           <xsl:for-each select="cl:warning">
  58.             <li>
  59.               <xsl:value-of select="current()"/>
  60.             </li>
  61.           </xsl:for-each>
  62.         </ul>
  63.       </td>
  64.     </tr>
  65.   </xsl:template>
  66. </xsl:stylesheet>
复制代码

Sample XSLT
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|BC Morning Website ( Best Deal Inc. 001 )  

GMT-8, 2025-8-25 15:15 , Processed in 0.024481 second(s), 17 queries .

Supported by Best Deal Online X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表