How to get data inside tag using xpath












-1















I'm using Scrapy to scrape a website. I have the following html structure



<dl>
<dt><b>Notice Date</b></dt>
<dd>12/17/2018<br>&nbsp;</dd>
<dt><b>Notice Type</b></dt>
<dd>Synopsis<br>&nbsp;</dd>
<dt><b>NAICS</b></dt>
<dd>238990 — All Other Specialty Trade Contractors<br>&nbsp;</dd>
<dt><b>Contracting Office</b></dt>
<dd>1108 South R Street Fort McCoy WI 54656-5142<br>&nbsp;</dd>
<dt><b>ZIP Code</b></dt>
<dd>54656-5142<br>&nbsp;</dd>
<dt><b>Solicitation Number</b></dt>
<dd>W911SA-18-B-2028<br>&nbsp;</dd>
<dt><b>Point of Contact</b></dt>
<dd>Jamie Gregar, Contract Specialist, Phone 6083881007 <br>&nbsp;</dd>
<dt><b>E-Mail Address</b></dt>
<dd><a href="mailto:jamie.j.gregar.civ@mail.mil">jamie.j.gregar.civ@mail.mil</a<br>&nbsp;</dd>
<dt><b>Small Business Set-Aside</b></dt>
<dd>HUBZone<br>&nbsp;</dd>
<dt><b>Description</b></dt>
<dd>some description here<br>&nbsp; </dd>
<dt><b>Web Link</b></dt>
<dd><a target="outside" href="https://www.fbo.gov/notices/54ba577b59c07b3757739e138b20ef3c">
Link To Document</a> <br>(https://www.fbo.gov/notices/54ba577b59c07b3757739e138b20ef3c)
<br>&nbsp; </dd>
<dt><b>Place of Performance</b></dt>
<dd><i>Address:</i> Laredo, TX </dd>
<dd><i>Zip Code:</i> 78040 </dd>
<dd><i>Country:</i> US <br>&nbsp; </dd>
<dt><b>Record</b> </dt>
<dd>SN05176005-F 20181219/181217230006 (fbodaily.com) <br>&nbsp; </dd>
<dt><b>Source</b></dt>
<dd><a target="fedbizopps" href="ftp://ftp.fbo.gov/FBOFeed20181217"> FedBizOpps Link to This Notice</a><br>(may not be valid after Archive Date) </dd>

</dl>


In the above structure, you can see the <dt> tag refers to the title of data and the <dd> tags follows to it, will contain relevant data and data may consists of different types (i.e. email addresses, text, web links).



So far I can get up to <dl> tag using xpath conventions. So can someone suggest me a way to get these data separately into the given fields using xpath starts from <dl> tag.










share|improve this question


















  • 2





    Show us how you tried. Share your current and desired output

    – Andersson
    Jan 2 at 16:35


















-1















I'm using Scrapy to scrape a website. I have the following html structure



<dl>
<dt><b>Notice Date</b></dt>
<dd>12/17/2018<br>&nbsp;</dd>
<dt><b>Notice Type</b></dt>
<dd>Synopsis<br>&nbsp;</dd>
<dt><b>NAICS</b></dt>
<dd>238990 — All Other Specialty Trade Contractors<br>&nbsp;</dd>
<dt><b>Contracting Office</b></dt>
<dd>1108 South R Street Fort McCoy WI 54656-5142<br>&nbsp;</dd>
<dt><b>ZIP Code</b></dt>
<dd>54656-5142<br>&nbsp;</dd>
<dt><b>Solicitation Number</b></dt>
<dd>W911SA-18-B-2028<br>&nbsp;</dd>
<dt><b>Point of Contact</b></dt>
<dd>Jamie Gregar, Contract Specialist, Phone 6083881007 <br>&nbsp;</dd>
<dt><b>E-Mail Address</b></dt>
<dd><a href="mailto:jamie.j.gregar.civ@mail.mil">jamie.j.gregar.civ@mail.mil</a<br>&nbsp;</dd>
<dt><b>Small Business Set-Aside</b></dt>
<dd>HUBZone<br>&nbsp;</dd>
<dt><b>Description</b></dt>
<dd>some description here<br>&nbsp; </dd>
<dt><b>Web Link</b></dt>
<dd><a target="outside" href="https://www.fbo.gov/notices/54ba577b59c07b3757739e138b20ef3c">
Link To Document</a> <br>(https://www.fbo.gov/notices/54ba577b59c07b3757739e138b20ef3c)
<br>&nbsp; </dd>
<dt><b>Place of Performance</b></dt>
<dd><i>Address:</i> Laredo, TX </dd>
<dd><i>Zip Code:</i> 78040 </dd>
<dd><i>Country:</i> US <br>&nbsp; </dd>
<dt><b>Record</b> </dt>
<dd>SN05176005-F 20181219/181217230006 (fbodaily.com) <br>&nbsp; </dd>
<dt><b>Source</b></dt>
<dd><a target="fedbizopps" href="ftp://ftp.fbo.gov/FBOFeed20181217"> FedBizOpps Link to This Notice</a><br>(may not be valid after Archive Date) </dd>

</dl>


In the above structure, you can see the <dt> tag refers to the title of data and the <dd> tags follows to it, will contain relevant data and data may consists of different types (i.e. email addresses, text, web links).



So far I can get up to <dl> tag using xpath conventions. So can someone suggest me a way to get these data separately into the given fields using xpath starts from <dl> tag.










share|improve this question


















  • 2





    Show us how you tried. Share your current and desired output

    – Andersson
    Jan 2 at 16:35
















-1












-1








-1








I'm using Scrapy to scrape a website. I have the following html structure



<dl>
<dt><b>Notice Date</b></dt>
<dd>12/17/2018<br>&nbsp;</dd>
<dt><b>Notice Type</b></dt>
<dd>Synopsis<br>&nbsp;</dd>
<dt><b>NAICS</b></dt>
<dd>238990 — All Other Specialty Trade Contractors<br>&nbsp;</dd>
<dt><b>Contracting Office</b></dt>
<dd>1108 South R Street Fort McCoy WI 54656-5142<br>&nbsp;</dd>
<dt><b>ZIP Code</b></dt>
<dd>54656-5142<br>&nbsp;</dd>
<dt><b>Solicitation Number</b></dt>
<dd>W911SA-18-B-2028<br>&nbsp;</dd>
<dt><b>Point of Contact</b></dt>
<dd>Jamie Gregar, Contract Specialist, Phone 6083881007 <br>&nbsp;</dd>
<dt><b>E-Mail Address</b></dt>
<dd><a href="mailto:jamie.j.gregar.civ@mail.mil">jamie.j.gregar.civ@mail.mil</a<br>&nbsp;</dd>
<dt><b>Small Business Set-Aside</b></dt>
<dd>HUBZone<br>&nbsp;</dd>
<dt><b>Description</b></dt>
<dd>some description here<br>&nbsp; </dd>
<dt><b>Web Link</b></dt>
<dd><a target="outside" href="https://www.fbo.gov/notices/54ba577b59c07b3757739e138b20ef3c">
Link To Document</a> <br>(https://www.fbo.gov/notices/54ba577b59c07b3757739e138b20ef3c)
<br>&nbsp; </dd>
<dt><b>Place of Performance</b></dt>
<dd><i>Address:</i> Laredo, TX </dd>
<dd><i>Zip Code:</i> 78040 </dd>
<dd><i>Country:</i> US <br>&nbsp; </dd>
<dt><b>Record</b> </dt>
<dd>SN05176005-F 20181219/181217230006 (fbodaily.com) <br>&nbsp; </dd>
<dt><b>Source</b></dt>
<dd><a target="fedbizopps" href="ftp://ftp.fbo.gov/FBOFeed20181217"> FedBizOpps Link to This Notice</a><br>(may not be valid after Archive Date) </dd>

</dl>


In the above structure, you can see the <dt> tag refers to the title of data and the <dd> tags follows to it, will contain relevant data and data may consists of different types (i.e. email addresses, text, web links).



So far I can get up to <dl> tag using xpath conventions. So can someone suggest me a way to get these data separately into the given fields using xpath starts from <dl> tag.










share|improve this question














I'm using Scrapy to scrape a website. I have the following html structure



<dl>
<dt><b>Notice Date</b></dt>
<dd>12/17/2018<br>&nbsp;</dd>
<dt><b>Notice Type</b></dt>
<dd>Synopsis<br>&nbsp;</dd>
<dt><b>NAICS</b></dt>
<dd>238990 — All Other Specialty Trade Contractors<br>&nbsp;</dd>
<dt><b>Contracting Office</b></dt>
<dd>1108 South R Street Fort McCoy WI 54656-5142<br>&nbsp;</dd>
<dt><b>ZIP Code</b></dt>
<dd>54656-5142<br>&nbsp;</dd>
<dt><b>Solicitation Number</b></dt>
<dd>W911SA-18-B-2028<br>&nbsp;</dd>
<dt><b>Point of Contact</b></dt>
<dd>Jamie Gregar, Contract Specialist, Phone 6083881007 <br>&nbsp;</dd>
<dt><b>E-Mail Address</b></dt>
<dd><a href="mailto:jamie.j.gregar.civ@mail.mil">jamie.j.gregar.civ@mail.mil</a<br>&nbsp;</dd>
<dt><b>Small Business Set-Aside</b></dt>
<dd>HUBZone<br>&nbsp;</dd>
<dt><b>Description</b></dt>
<dd>some description here<br>&nbsp; </dd>
<dt><b>Web Link</b></dt>
<dd><a target="outside" href="https://www.fbo.gov/notices/54ba577b59c07b3757739e138b20ef3c">
Link To Document</a> <br>(https://www.fbo.gov/notices/54ba577b59c07b3757739e138b20ef3c)
<br>&nbsp; </dd>
<dt><b>Place of Performance</b></dt>
<dd><i>Address:</i> Laredo, TX </dd>
<dd><i>Zip Code:</i> 78040 </dd>
<dd><i>Country:</i> US <br>&nbsp; </dd>
<dt><b>Record</b> </dt>
<dd>SN05176005-F 20181219/181217230006 (fbodaily.com) <br>&nbsp; </dd>
<dt><b>Source</b></dt>
<dd><a target="fedbizopps" href="ftp://ftp.fbo.gov/FBOFeed20181217"> FedBizOpps Link to This Notice</a><br>(may not be valid after Archive Date) </dd>

</dl>


In the above structure, you can see the <dt> tag refers to the title of data and the <dd> tags follows to it, will contain relevant data and data may consists of different types (i.e. email addresses, text, web links).



So far I can get up to <dl> tag using xpath conventions. So can someone suggest me a way to get these data separately into the given fields using xpath starts from <dl> tag.







html xpath scrapy






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 2 at 15:29









Vajira PrabuddhakaVajira Prabuddhaka

161317




161317








  • 2





    Show us how you tried. Share your current and desired output

    – Andersson
    Jan 2 at 16:35
















  • 2





    Show us how you tried. Share your current and desired output

    – Andersson
    Jan 2 at 16:35










2




2





Show us how you tried. Share your current and desired output

– Andersson
Jan 2 at 16:35







Show us how you tried. Share your current and desired output

– Andersson
Jan 2 at 16:35














1 Answer
1






active

oldest

votes


















0














for dt in response.css('dt'):
key = dt.get()
value = dt.xpath('./following::dd[1]').get()


You might want to clean the data further, extracting only text either by using the .//text() XPath or extract_text().






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54008984%2fhow-to-get-data-inside-dl-tag-using-xpath%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    for dt in response.css('dt'):
    key = dt.get()
    value = dt.xpath('./following::dd[1]').get()


    You might want to clean the data further, extracting only text either by using the .//text() XPath or extract_text().






    share|improve this answer




























      0














      for dt in response.css('dt'):
      key = dt.get()
      value = dt.xpath('./following::dd[1]').get()


      You might want to clean the data further, extracting only text either by using the .//text() XPath or extract_text().






      share|improve this answer


























        0












        0








        0







        for dt in response.css('dt'):
        key = dt.get()
        value = dt.xpath('./following::dd[1]').get()


        You might want to clean the data further, extracting only text either by using the .//text() XPath or extract_text().






        share|improve this answer













        for dt in response.css('dt'):
        key = dt.get()
        value = dt.xpath('./following::dd[1]').get()


        You might want to clean the data further, extracting only text either by using the .//text() XPath or extract_text().







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 16 at 11:42









        GallaecioGallaecio

        96011023




        96011023
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54008984%2fhow-to-get-data-inside-dl-tag-using-xpath%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            Npm cannot find a required file even through it is in the searched directory

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith