所以我正在尝试抓取 www.latimes.com 的某个部分作为练习,而我选择"trb_outfit_group trb_outfit_section"的部分似乎不会刮擦,有什么建议吗?如果需要,我可以发布 latimes.com HTML。
这是我的代码:
require'nokogiri'
require'curb'
http = Curl.get("http://www.latimes.com/") do |http|
http.headers['User-Agent'] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10; rv:33.0) Gecko/20100101 Firefox/33.0"
end
html = Nokogiri::HTML(http.body_str)
html.css("trb_outfit_group trb_outfit_section").each do |node|
puts node.inner_html "nn"
end
这是我尝试抓取的代码:
<section class="trb_outfit_group trb_outfit_section" data-content-limit="5" data-role="imgsize_ratiosizecontainer" data-content-briefs="false" data-outfits-art-disable=""><ul class="trb_outfit_group_list"><li class="trb_outfit_group_list_item" data-content-id="83268726" data-content-slug="la-me-ln-san-diego-water-protest-20150410" data-content-title="San Diego water officials protest proposed cutback rules" data-content-section="LOCAL" data-content-type="story" data-content-thumbnail="http://www.trbimg.com/img-55285596/turbine/la-me-ln-san-diego-water-protest-20150410" data-content-url="/local/lanow/la-me-ln-san-diego-water-protest-20150410-story.html"> <a imgratio="1x1" imgwidth="100" imgheight="100" href="/local/lanow/la-me-ln-san-diego-water-protest-20150410-story.html#navtype=outfit" data-role="imgsize_item" class="trb_outfit_group_list_item_figure"><img src="http://www.trbimg.com/img-55285596/turbine/la-me-ln-san-diego-water-protest-20150410/100/100x100" data-height="100" data-width="100" data-ratio="1x1" data-baseurl="http://www.trbimg.com/img-55285596/turbine/la-me-ln-san-diego-water-protest-20150410" alt="San Diego water officials protest proposed cutback rules" class="trb_outfit_group_list_item_img" title="San Diego water officials protest proposed cutback rules" data-content-naturalwidth="2048" data-content-naturalheight="1365"></a><section class="trb_outfit_group_list_item_body"><div class="trb_outfit_group_item_label" data-content-label=""><span class="trb_outfit_categorySectionHeading"><a class="trb_outfit_categorySectionHeading_a" href="/local/lanow/#navtype=outfit">L.A. Now</a></span> <time class="trb_outfit_categorySectionHeading_date" datetime="2015-04-10T15:37:00PDT" data-datetime-timezone="PDT" data-datetime-month="April" data-datetime-monthshort="Apr." data-datetime-day="10" data-datetime-year="2015" data-datetime-weekday="Friday" data-datetime-weekdayshort="Fri." data-datetime-fullclock="3:37:00 PM" data-datetime-clock="3:37 PM" data-datetime-hour="3 PM" data-datetime-today="" data-datetime-daydiff="-1 days left"></time> <span class="trb_outfits_metabuckets_3"></span></div><span class="trb_outfit_relatedListTitle"><a href="/local/lanow/la-me-ln-san-diego-water-protest-20150410-story.html#navtype=outfit" class="trb_outfit_relatedListTitle_a">San Diego water officials protest proposed cutback rules</a><span class="trb_outfits_metabuckets"><span class="trb_outfits_metabuckets_1"></span></span></span></section></li><li class="trb_outfit_group_list_item" data-content-id="83268337" data-content-slug="la-na-nn-kansas-army-bomb-plot-20150410" data-content-title="Kansas man charged in plot to bomb U.S. army base, join Islamic State" data-content-section="Nation" data-content-type="story" data-content-thumbnail="http://www.trbimg.com/img-55283d7f/turbine/la-na-nn-kansas-army-bomb-plot-20150410" data-content-url="/nation/nationnow/la-na-nn-kansas-army-bomb-plot-20150410-story.html"> <a imgratio="1x1" imgwidth="100" imgheight="100" href="/nation/nationnow/la-na-nn-kansas-army-bomb-plot-20150410-story.html#navtype=outfit" data-role="imgsize_item" class="trb_outfit_group_list_item_figure"><img src="http://www.trbimg.com/img-55283d7f/turbine/la-na-nn-kansas-army-bomb-plot-20150410/100/100x100" data-height="100" data-width="100" data-ratio="1x1" data-baseurl="http://www.trbimg.com/img-55283d7f/turbine/la-na-nn-kansas-army-bomb-plot-20150410" alt="Kansas man charged in plot to bomb U.S. army base, join Islamic State" class="trb_outfit_group_list_item_img" title="Kansas man charged in plot to bomb U.S. army base, join Islamic State" data-content-naturalwidth="1024" data-content-naturalheight="725"></a><section class="trb_outfit_group_list_item_body"><div class="trb_outfit_group_item_label" data-content-label=""><span class="trb_outfit_categorySectionHeading"><a class="trb_outfit_categorySectionHeading_a" href="/nation/nationnow/#navtype=outfit">Nation Now</a></span> <time class="trb_outfit_categorySectionHeading_date" datetime="2015-04-10T15:16:00PDT" data-datetime-timezone="PDT" data-datetime-month="April" data-datetime-monthshort="Apr." data-datetime-day="10" data-datetime-year="2015" data-datetime-weekday="Friday" data-datetime-weekdayshort="Fri." data-datetime-fullclock="3:16:00 PM" data-datetime-clock="3:16 PM" data-datetime-hour="3 PM" data-datetime-today="" data-datetime-daydiff="-1 days left"></time> <span class="trb_outfits_metabuckets_3"></span></div><span class="trb_outfit_relatedListTitle"><a href="/nation/nationnow/la-na-nn-kansas-army-bomb-plot-20150410-story.html#navtype=outfit" class="trb_outfit_relatedListTitle_a">Kansas man charged in plot to bomb U.S. army base, join Islamic State</a><span class="trb_outfits_metabuckets"><span class="trb_outfits_metabuckets_1"></span></span></span></section></li><li class="trb_outfit_group_list_item" data-content-id="83263689" data-content-slug="la-na-south-carolina-shooting-20150410" data-content-title="South Carolina shooting case will head to a grand jury" data-content-section="Nation" data-content-type="story" data-content-thumbnail="http://www.trbimg.com/img-55281f7d/turbine/la-na-south-carolina-shooting-20150410" data-content-url="/nation/la-na-south-carolina-shooting-20150410-story.html"> <a imgratio="1x1" imgwidth="100" imgheight="100" href="/nation/la-na-south-carolina-shooting-20150410-story.html#navtype=outfit" data-role="imgsize_item" class="trb_outfit_group_list_item_figure"><img src="http://www.trbimg.com/img-55281f7d/turbine/la-na-south-carolina-shooting-20150410/100/100x100" data-height="100" data-width="100" data-ratio="1x1" data-baseurl="http://www.trbimg.com/img-55281f7d/turbine/la-na-south-carolina-shooting-20150410" alt="South Carolina shooting case will head to a grand jury" class="trb_outfit_group_list_item_img" title="South Carolina shooting case will head to a grand jury" data-content-naturalwidth="1600" data-content-naturalheight="900"></a><section class="trb_outfit_group_list_item_body"><div class="trb_outfit_group_item_label" data-content-label=""><span class="trb_outfit_categorySectionHeading"><a class="trb_outfit_categorySectionHeading_a" href="/nation/#navtype=outfit">Nation</a></span> <time class="trb_outfit_categorySectionHeading_date" datetime="2015-04-10T13:14:00PDT" data-datetime-timezone="PDT" data-datetime-month="April" data-datetime-monthshort="Apr." data-datetime-day="10" data-datetime-year="2015" data-datetime-weekday="Friday" data-datetime-weekdayshort="Fri." data-datetime-fullclock="1:14:00 PM" data-datetime-clock="1:14 PM" data-datetime-hour="1 PM" data-datetime-today="" data-datetime-daydiff="-1 days left"></time> <span class="trb_outfits_metabuckets_3"></span></div><span class="trb_outfit_relatedListTitle"><a href="/nation/la-na-south-carolina-shooting-20150410-story.html#navtype=outfit" class="trb_outfit_relatedListTitle_a">South Carolina shooting case will head to a grand jury</a><span class="trb_outfits_metabuckets"><span class="trb_outfits_metabuckets_1"></span></span></span></section></li><li class="trb_outfit_group_list_item" data-content-id="83265720" data-content-slug="la-me-ln-parking-reform-fines-20150410" data-content-title="Parking reform group recommends Los Angeles slash many fines" data-content-section="LOCAL" data-content-type="story" data-content-thumbnail="http://www.trbimg.com/img-55283cbd/turbine/la-me-ln-parking-reform-fines-20150410" data-content-url="/local/lanow/la-me-ln-parking-reform-fines-20150410-story.html"> <a imgratio="1x1" imgwidth="100" imgheight="100" href="/local/lanow/la-me-ln-parking-reform-fines-20150410-story.html#navtype=outfit" data-role="imgsize_item" class="trb_outfit_group_list_item_figure"><img src="http://www.trbimg.com/img-55283cbd/turbine/la-me-ln-parking-reform-fines-20150410/100/100x100" data-height="100" data-width="100" data-ratio="1x1" data-baseurl="http://www.trbimg.com/img-55283cbd/turbine/la-me-ln-parking-reform-fines-20150410" alt="Parking reform group recommends Los Angeles slash many fines" class="trb_outfit_group_list_item_img" title="Parking reform group recommends Los Angeles slash many fines" data-content-naturalwidth="2000" data-content-naturalheight="1518"></a><section class="trb_outfit_group_list_item_body"><div class="trb_outfit_group_item_label" data-content-label=""><span class="trb_outfit_categorySectionHeading"><a class="trb_outfit_categorySectionHeading_a" href="/local/lanow/#navtype=outfit">L.A. Now</a></span> <time class="trb_outfit_categorySectionHeading_date" datetime="2015-04-10T14:01:00PDT" data-datetime-timezone="PDT" data-datetime-month="April" data-datetime-monthshort="Apr." data-datetime-day="10" data-datetime-year="2015" data-datetime-weekday="Friday" data-datetime-weekdayshort="Fri." data-datetime-fullclock="2:01:00 PM" data-datetime-clock="2:01 PM" data-datetime-hour="2 PM" data-datetime-today="" data-datetime-daydiff="-1 days left"></time> <span class="trb_outfits_metabuckets_3"></span></div><span class="trb_outfit_relatedListTitle"><a href="/local/lanow/la-me-ln-parking-reform-fines-20150410-story.html#navtype=outfit" class="trb_outfit_relatedListTitle_a">Parking reform group recommends Los Angeles slash many fines</a><span class="trb_outfits_metabuckets"><span class="trb_outfits_metabuckets_1"></span></span></span></section></li><li class="trb_outfit_group_list_item" data-content-id="83266310" data-content-slug="la-fg-obama-castro-embassies-20150410" data-content-title="Obama, Raul Castro chat about opening embassies in step to normal ties" data-content-section="World" data-content-type="story" data-content-thumbnail="http://www.trbimg.com/img-55281a2f/turbine/la-fg-obama-castro-embassies-20150410" data-content-url="/world/mexico-americas/la-fg-obama-castro-embassies-20150410-story.html"> <a imgratio="1x1" imgwidth="100" imgheight="100" href="/world/mexico-americas/la-fg-obama-castro-embassies-20150410-story.html#navtype=outfit" data-role="imgsize_item" class="trb_outfit_group_list_item_figure"><img src="http://www.trbimg.com/img-55281a2f/turbine/la-fg-obama-castro-embassies-20150410/100/100x100" data-height="100" data-width="100" data-ratio="1x1" data-baseurl="http://www.trbimg.com/img-55281a2f/turbine/la-fg-obama-castro-embassies-20150410" alt="Obama, Raul Castro chat about opening embassies in step to normal ties" class="trb_outfit_group_list_item_img" title="Obama, Raul Castro chat about opening embassies in step to normal ties" data-content-naturalwidth="2048" data-content-naturalheight="1298"></a><section class="trb_outfit_group_list_item_body"><div class="trb_outfit_group_item_label" data-content-label=""><span class="trb_outfit_categorySectionHeading"><a class="trb_outfit_categorySectionHeading_a" href="/world/mexico-americas/#navtype=outfit">Mexico & the Americas</a></span> <time class="trb_outfit_categorySectionHeading_date" datetime="2015-04-10T12:19:00PDT" data-datetime-timezone="PDT" data-datetime-month="April" data-datetime-monthshort="Apr." data-datetime-day="10" data-datetime-year="2015" data-datetime-weekday="Friday" data-datetime-weekdayshort="Fri." data-datetime-fullclock="12:19:00 PM" data-datetime-clock="12:19 PM" data-datetime-hour="12 PM" data-datetime-today="" data-datetime-daydiff="-1 days left"></time> <span class="trb_outfits_metabuckets_3"></span></div><span class="trb_outfit_relatedListTitle"><a href="/world/mexico-americas/la-fg-obama-castro-embassies-20150410-story.html#navtype=outfit" class="trb_outfit_relatedListTitle_a">Obama, Raul Castro chat about opening embassies in step to normal ties</a><span class="trb_outfits_metabuckets"><span class="trb_outfits_metabuckets_1"></span></span></span></section></li></ul></section><div id="trb_ad_outfitAd_1_2_/" class="trb_gptAd" data-role="adloader_ad" data-state="adloader_loaded" data-withinviewport-options="bottomOffset=100&topOffset=1000000" data-adloader-position="outfitAd" data-adloader-size="300x250" data-adloader-adtype="cubecombo" data-adloader-label=""><div style="border: 0pt none;" id="google_ads_iframe_/4011/trb.latimes/hp_1__container__"><iframe src="javascript:"<html><body style='background:transparent'></body></html>"" style="border: 0px none; vertical-align: bottom;" marginheight="0" marginwidth="0" scrolling="no" name="google_ads_iframe_/4011/trb.latimes/hp_1" id="google_ads_iframe_/4011/trb.latimes/hp_1" frameborder="0" height="250" width="300"></iframe></div><iframe src="javascript:"<html><body style='background:transparent'></body></html>"" style="border: 0px none; vertical-align: bottom; visibility: hidden; display: none;" marginheight="0" marginwidth="0" scrolling="no" name="google_ads_iframe_/4011/trb.latimes/hp_1__hidden__" id="google_ads_iframe_/4011/trb.latimes/hp_1__hidden__" frameborder="0" height="0" width="0"></iframe></div>
<section class="trb_outfit_list trb_outfit_section">
<div class="trb_outfit_list_wrapper">
<span class="trb_outfit_listHeading">Afternoon Report</span>
<a class="trb_outfit_callToAction" href="/latest/#navtype=outfit">latest headlines</a><ul class="trb_outfit_list_list"><li class="trb_outfit_list_headline" data-content-id="83269044" data-content-slug="la-me-ln-suspect-carjacked-taxi-20150410" data-content-title="Police chase taxi through South L.A." data-content-section="LOCAL" data-content-type="story" data-content-thumbnail="http://www.trbimg.com/img-55284f92/turbine/la-me-ln-suspect-carjacked-taxi-20150410" data-content-url="/local/lanow/la-me-ln-suspect-carjacked-taxi-20150410-story.html"><div class="trb_outfit_categorySectionHeading_container"><span class="trb_outfit_categorySectionHeading"><a href="/local/lanow/#navtype=outfit" class="trb_outfit_categorySectionHeading_a">L.A. Now</a></span><time class="trb_outfit_categorySectionHeading_date" datetime="2015-04-10T15:51:00PDT" data-datetime-timezone="PDT" data-datetime-month="April" data-datetime-monthshort="Apr." data-datetime-day="10" data-datetime-year="2015" data-datetime-weekday="Friday" data-datetime-weekdayshort="Fri." data-datetime-fullclock="3:51:00 PM" data-datetime-clock="3:51 PM" data-datetime-hour="3 PM" data-datetime-today="" data-datetime-daydiff="-1 days left"></time></div> <a href="/local/lanow/la-me-ln-suspect-carjacked-taxi-20150410-story.html#navtype=outfit" class="trb_outfit_list_headline_a"><span class="trb_outfit_list_headline_a_text">Police chase taxi through South L.A.</span></a><span class="trb_outfits_metabuckets"><span class="trb_outfits_metabuckets_1"></span><span class="trb_outfits_metabuckets_3"></span></span></li><li class="trb_outfit_list_headline" data-content-id="83268721" data-content-slug="la-me-ln-robert-durst-charged-in-handgun-case-20150410" data-content-title="Robert Durst charged in federal handgun case" data-content-section="LOCAL" data-content-type="story" data-content-thumbnail="http://www.trbimg.com/img-55284bfd/turbine/la-me-ln-robert-durst-charged-in-handgun-case-20150410" data-content-url="/local/lanow/la-me-ln-robert-durst-charged-in-handgun-case-20150410-story.html"><div class="trb_outfit_categorySectionHeading_container"><span class="trb_outfit_categorySectionHeading"><a href="/local/lanow/#navtype=outfit" class="trb_outfit_categorySectionHeading_a">L.A. Now</a></span><time class="trb_outfit_categorySectionHeading_date" datetime="2015-04-10T15:10:00PDT" data-datetime-timezone="PDT" data-datetime-month="April" data-datetime-monthshort="Apr." data-datetime-day="10" data-datetime-year="2015" data-datetime-weekday="Friday" data-datetime-weekdayshort="Fri." data-datetime-fullclock="3:10:00 PM" data-datetime-clock="3:10 PM" data-datetime-hour="3 PM" data-datetime-today="" data-datetime-daydiff="-1 days left"></time></div> <a href="/local/lanow/la-me-ln-robert-durst-charged-in-handgun-case-20150410-story.html#navtype=outfit" class="trb_outfit_list_headline_a"><span class="trb_outfit_list_headline_a_text">Robert Durst charged in federal handgun case</span></a><span class="trb_outfits_metabuckets"><span class="trb_outfits_metabuckets_1"></span><span class="trb_outfits_metabuckets_3"></span></span></li><li class="trb_outfit_list_headline" data-content-id="83267543" data-content-slug="la-na-nn-police-identify-suspect-census-bureau-20150410" data-content-title="Suspect in Census Bureau shooting identified; slain guard was Army veteran" data-content-section="Nation" data-content-type="story" data-content-thumbnail="http://www.trbimg.com/img-55283a24/turbine/la-na-nn-police-identify-suspect-census-bureau-20150410" data-content-url="/nation/nationnow/la-na-nn-police-identify-suspect-census-bureau-20150410-story.html"><div class="trb_outfit_categorySectionHeading_container"><span class="trb_outfit_categorySectionHeading"><a href="/nation/nationnow/#navtype=outfit" class="trb_outfit_categorySectionHeading_a">Nation Now</a></span><time class="trb_outfit_categorySectionHeading_date" datetime="2015-04-10T14:16:00PDT" data-datetime-timezone="PDT" data-datetime-month="April" data-datetime-monthshort="Apr." data-datetime-day="10" data-datetime-year="2015" data-datetime-weekday="Friday" data-datetime-weekdayshort="Fri." data-datetime-fullclock="2:16:00 PM" data-datetime-clock="2:16 PM" data-datetime-hour="2 PM" data-datetime-today="" data-datetime-daydiff="-1 days left"></time></div> <a href="/nation/nationnow/la-na-nn-police-identify-suspect-census-bureau-20150410-story.html#navtype=outfit" class="trb_outfit_list_headline_a"><span class="trb_outfit_list_headline_a_text">Suspect in Census Bureau shooting identified; slain guard was Army veteran</span></a><span class="trb_outfits_metabuckets"><span class="trb_outfits_metabuckets_1"></span><span class="trb_outfits_metabuckets_3"></span></span></li><li class="trb_outfit_list_headline" data-content-id="83261882" data-content-slug="la-na-nn-illinois-tornado-20150409" data-content-title="Violent tornado kills 2 in Illinois, flattens dozens of homes" data-content-section="Nation" data-content-type="story" data-content-thumbnail="http://www.trbimg.com/img-5527531f/turbine/la-na-nn-illinois-tornado-20150409" data-content-url="/nation/nationnow/la-na-nn-illinois-tornado-20150409-story.html"><div class="trb_outfit_categorySectionHeading_container"><span class="trb_outfit_categorySectionHeading"><a href="/nation/nationnow/#navtype=outfit" class="trb_outfit_categorySectionHeading_a">Nation Now</a></span><time class="trb_outfit_categorySectionHeading_date" datetime="2015-04-10T15:21:00PDT" data-datetime-timezone="PDT" data-datetime-month="April" data-datetime-monthshort="Apr." data-datetime-day="10" data-datetime-year="2015" data-datetime-weekday="Friday" data-datetime-weekdayshort="Fri." data-datetime-fullclock="3:21:00 PM" data-datetime-clock="3:21 PM" data-datetime-hour="3 PM" data-datetime-today="" data-datetime-daydiff="-1 days left"></time></div> <a href="/nation/nationnow/la-na-nn-illinois-tornado-20150409-story.html#navtype=outfit" class="trb_outfit_list_headline_a"><span class="trb_outfit_list_headline_a_text">Violent tornado kills 2 in Illinois, flattens dozens of homes</span></a><span class="trb_outfits_metabuckets"><span class="trb_outfits_metabuckets_1"></span><span class="trb_outfits_metabuckets_3"></span></span></li><li class="trb_outfit_list_headline" data-content-id="83267604" data-content-slug="la-et-mn-harvey-weinstein-allegations-groping-battilana-20150410" data-content-title="Harvey Weinstein won&apos;t be charged in alleged groping incident" data-content-section="ARTS & ENTERTAINMENT" data-content-type="story" data-content-thumbnail="http://www.trbimg.com/img-552836dc/turbine/la-et-mn-harvey-weinstein-allegations-groping-battilana-20150410" data-content-url="/entertainment/movies/moviesnow/la-et-mn-harvey-weinstein-allegations-groping-battilana-20150410-story.html"><div class="trb_outfit_categorySectionHeading_container"><span class="trb_outfit_categorySectionHeading"><a href="/entertainment/movies/moviesnow/#navtype=outfit" class="trb_outfit_categorySectionHeading_a">Movies Now</a></span><time class="trb_outfit_categorySectionHeading_date" datetime="2015-04-10T13:29:00PDT" data-datetime-timezone="PDT" data-datetime-month="April" data-datetime-monthshort="Apr." data-datetime-day="10" data-datetime-year="2015" data-datetime-weekday="Friday" data-datetime-weekdayshort="Fri." data-datetime-fullclock="1:29:00 PM" data-datetime-clock="1:29 PM" data-datetime-hour="1 PM" data-datetime-today="" data-datetime-daydiff="-1 days left"></time></div> <a href="/entertainment/movies/moviesnow/la-et-mn-harvey-weinstein-allegations-groping-battilana-20150410-story.html#navtype=outfit" class="trb_outfit_list_headline_a"><span class="trb_outfit_list_headline_a_text">Harvey Weinstein won't be charged in alleged groping incident</span></a><span class="trb_outfits_metabuckets"><span class="trb_outfits_metabuckets_1"></span><span class="trb_outfits_metabuckets_3"></span></span></li><li class="trb_outfit_list_headline" data-content-id="83263769" data-content-slug="la-me-ln-deadly-harbor-crash-20150410" data-content-title="Car&apos;s deadly plunge into harbor investigated as accident" data-content-section="LOCAL" data-content-type="story" data-content-thumbnail="http://www.trbimg.com/img-5527d47d/turbine/la-me-ln-deadly-harbor-crash-20150410" data-content-url="/local/lanow/la-me-ln-deadly-harbor-crash-20150410-story.html"><div class="trb_outfit_categorySectionHeading_container"><span class="trb_outfit_categorySectionHeading"><a href="/local/lanow/#navtype=outfit" class="trb_outfit_categorySectionHeading_a">L.A. Now</a></span><time class="trb_outfit_categorySectionHeading_date" datetime="2015-04-10T12:55:00PDT" data-datetime-timezone="PDT" data-datetime-month="April" data-datetime-monthshort="Apr." data-datetime-day="10" data-datetime-year="2015" data-datetime-weekday="Friday" data-datetime-weekdayshort="Fri." data-datetime-fullclock="12:55:00 PM" data-datetime-clock="12:55 PM" data-datetime-hour="12 PM" data-datetime-today="" data-datetime-daydiff="-1 days left"></time></div> <a href="/local/lanow/la-me-ln-deadly-harbor-crash-20150410-story.html#navtype=outfit" class="trb_outfit_list_headline_a"><span class="trb_outfit_list_headline_a_text">Car's deadly plunge into harbor investigated as accident</span></a><span class="trb_outfits_metabuckets"><span class="trb_outfits_metabuckets_1"></span><span class="trb_outfits_metabuckets_3"></span></span></li></ul>
</div>
</section><section class="trb_outfit_group trb_outfit_section" data-content-limit="2" data-role="imgsize_ratiosizecontainer" data-content-briefs="false" data-outfits-art-disable=""><div class="trb_outfit_section_header"><h3 class="trb_outfit_section_title">LACMA at 50</h3><a class="trb_outfit_callToAction" href="http://www.latimes.com/entertainment/la-et-cm-lacma-at-50-main-htmlstory.html">Full Coverage</a></div><ul class="trb_outfit_group_list"><li class="trb_outfit_group_list_item" data-content-id="83252513" data-content-slug="la-et-cm-ca-lacma-academy-museum-20150412" data-content-title="LACMA sees the big picture as Academy Museum moves in next door" data-content-section="ARTS & ENTERTAINMENT" data-content-type="story" data-content-thumbnail="http://www.trbimg.com/img-5526e11b/turbine/la-et-cm-ca-lacma-academy-museum-20150412" data-content-url="/entertainment/arts/la-et-cm-ca-lacma-academy-museum-20150412-story.html"> <a imgratio="16x9" imgwidth="100" imgheight="100" href="/entertainment/arts/la-et-cm-ca-lacma-academy-museum-20150412-story.html#navtype=outfit" data-role="imgsize_item" class="trb_outfit_group_list_item_figure"><img src="http://www.trbimg.com/img-5526e11b/turbine/la-et-cm-ca-lacma-academy-museum-20150412/100/100x56" data-height="100" data-width="100" data-ratio="16x9" data-baseurl="http://www.trbimg.com/img-5526e11b/turbine/la-et-cm-ca-lacma-academy-museum-20150412" alt="LACMA sees the big picture as Academy Museum moves in next door" class="trb_outfit_group_list_item_img" title="LACMA sees the big picture as Academy Museum moves in next door" data-content-naturalwidth="2048" data-content-naturalheight="1270"></a><section class="trb_outfit_group_list_item_body"><div class="trb_outfit_group_item_label" data-content-label=""><span class="trb_outfit_categorySectionHeading"><a class="trb_outfit_categorySectionHeading_a" href="/entertainment/arts/#navtype=outfit">ARTS & CULTURE</a></span> <time class="trb_outfit_categorySectionHeading_date" datetime="2015-04-10T12:00:00PDT" data-datetime-timezone="PDT" data-datetime-month="April" data-datetime-monthshort="Apr." data-datetime-day="10" data-datetime-year="2015" data-datetime-weekday="Friday" data-datetime-weekdayshort="Fri." data-datetime-fullclock="12:00:00 PM" data-datetime-clock="12:00 PM" data-datetime-hour="12 PM" data-datetime-today="" data-datetime-daydiff="-1 days left"></time> <span class="trb_outfits_metabuckets_3"></span></div><span class="trb_outfit_relatedListTitle"><a href="/entertainment/arts/la-et-cm-ca-lacma-academy-museum-20150412-story.html#navtype=outfit" class="trb_outfit_relatedListTitle_a">LACMA sees the big picture as Academy Museum moves in next door</a><span class="trb_outfits_metabuckets"><span class="trb_outfits_metabuckets_1"></span></span></span></section></li><li class="trb_outfit_group_list_item" data-content-id="83268414" data-content-slug="la-explore-art-critic-christopher-knights-50-masterpieces-20150410" data-content-title="Explore 50 masterpieces with art critic Christopher Knight" data-content-section="ARTS & ENTERTAINMENT" data-content-type="storylink" data-content-thumbnail="http://www.trbimg.com/img-55283f7b/turbine/la-explore-art-critic-christopher-knights-50-masterpieces-20150410" data-content-url="http://graphics.latimes.com/lacma-amazing-art-collection/"> <a imgratio="16x9" imgwidth="100" imgheight="100" href="http://graphics.latimes.com/lacma-amazing-art-collection/" data-role="imgsize_item" class="trb_outfit_group_list_item_figure"><img src="http://www.trbimg.com/img-55283f7b/turbine/la-explore-art-critic-christopher-knights-50-masterpieces-20150410/100/100x56" data-height="100" data-width="100" data-ratio="16x9" data-baseurl="http://www.trbimg.com/img-55283f7b/turbine/la-explore-art-critic-christopher-knights-50-masterpieces-20150410" alt="Explore 50 masterpieces with art critic Christopher Knight" class="trb_outfit_group_list_item_img" title="Explore 50 masterpieces with art critic Christopher Knight" data-content-naturalwidth="1600" data-content-naturalheight="900"></a><section class="trb_outfit_group_list_item_body"><div class="trb_outfit_group_item_label" data-content-label=""><span class="trb_outfit_categorySectionHeading"><a class="trb_outfit_categorySectionHeading_a" href="/entertainment/arts/#navtype=outfit">ARTS & CULTURE</a></span> <time class="trb_outfit_categorySectionHeading_date" datetime="2015-04-10T14:22:00PDT" data-datetime-timezone="PDT" data-datetime-month="April" data-datetime-monthshort="Apr." data-datetime-day="10" data-datetime-year="2015" data-datetime-weekday="Friday" data-datetime-weekdayshort="Fri." data-datetime-fullclock="2:22:00 PM" data-datetime-clock="2:22 PM" data-datetime-hour="2 PM" data-datetime-today="" data-datetime-daydiff="-1 days left"></time> <span class="trb_outfits_metabuckets_3"></span></div><span class="trb_outfit_relatedListTitle"><a href="http://graphics.latimes.com/lacma-amazing-art-collection/" class="trb_outfit_relatedListTitle_a">Explore 50 masterpieces with art critic Christopher Knight</a><span class="trb_outfits_metabuckets"><span class="trb_outfits_metabuckets_1"></span></span></span></section></li></ul></section>
考虑一下:
require'nokogiri'
require'curb'
url = Curl.get("http://www.latimes.com/") do |http|
http.headers['User-Agent'] = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10; rv:33.0) Gecko/20100101 Firefox/33.0"
end
html = Nokogiri::HTML(url.body_str)
puts html.css(".trb_outfit_group.trb_outfit_section").inner_html
注意:
- 类的 CSS 选择器是错误的。
- 要获得
inner_html
,您无需遍历节点。 - 将变量重命名
http
为url
,因为它隐藏了迭代器中使用的局部变量。