나는 Scrapy를 사용하여 article을 얻고 있습니다.치료법을 사용하여 xpath를 더 선택적으로 만드는 방법은 무엇입니까?
>>> articletext = hxs.select("//span[@id='articleText']")
>>> for p in articletext.select('.//p'):
... print p.extract()
...
<p class="byline">By Patricia Reaney</p>
<p>
<span class="location">NEW YORK</span> |
<span class="timestamp">Tue Apr 3, 2012 6:19am EDT</span>
</p>
<p><span class="articleLocation">NEW YORK</span> (Reuters) - Ba
track of finances, shopping and searching for jobs are the mai
et users around the globe, according to a new international
survey.</p>
<p>Nearly 60 percent of people in 24 countries used the web to
account and other financial assets in the past 90 days, making
ar use of the Internet.</p>
<p>Shopping was not far behind at 48 percent, the Ipsos poll fo
and 41 percent went online in search of a job.</p>
<p>"It is easy. You can do it any time of the day and most of t
on't have fees," said Keren Gottfried, research manager for Ips
Affairs, about banking online.</p>
필자 만 회람, 타임 스탬프 및 기사 위치를 제거하고 기사 만 남기고 싶습니다. 또는 기사를 추출하는 것이 더 좋습니다. 어떻게해야합니까?
이렇게 할 때 반환되는 값은 "
"입니다. 당신은 하루 중 언제든지 할 수 있고 대부분 에는 요금이 없습니다 "라고 Irene 업무 담당 연구 매니저 인 Keren Gottfried는 온라인 뱅킹에 대해 말했다.
" – Jean그 이상한 것은 실생활에 해당하는 코드 예제입니다. 그때? 아니면 출력 결과를 테스트하고 있습니까? 그'p'는 제 예제에서는 4 번째지만, 6 번째 샘플은 당신 것입니다. 어떤 다른 일이 일어날 수 있습니다 제안합니다. –
오 코드 예제가 출력되었습니다. 주어진 링크에서 소스 코드를 사용합니다. 귀하의 방법은 작동하지만, 나는 깨달았다. 나는 focusparagraph = hxs.select ("// span [@ class = 'focusParagraph']/p)로 내 문제를 해결했다. articletext = hxs.select ("// span [@ id = 'articleText']/p) focusparagraph P에 대한 문서 = ' : ftext p.extract =() articletext에 대한 P : atext p.extract =() 문서 + = atext 인쇄 ftext + 문서 – Jean