мой код паука:
Код: Выделить всё
from ..items import NewsArticleItem, NewsArticleItemLoader
from .base import SitemapIndexSpider
class IndianExpressSpider(SitemapIndexSpider):
name = "indianexpress"
sitemap_type = "daily"
allowed_domains = ["indianexpress.com"]
sitemap_patterns = [
"https://indianexpress.com/sitemap.xml?yyyy={year}&mm={month}&dd={day}"
]
sitemap_rules = [(r"/article/business/", "parse")]
def parse(self, response):
article = NewsArticleItemLoader(item=NewsArticleItem(), response=response)
# content
article.add_css("title", "h1::text")
article.add_css("description", "h2.synopsis::text")
article.add_css("author", "div.editor a::text")
# This XPath should return nothing but still gives the previous result
article.add_xpath("article_text", '')
# dates
article.add_css(
"date_published",
'meta[itemprop="datePublished"]::attr(content)',
)
article.add_css(
"date_modified",
'meta[itemprop="dateModified"]::attr(content)',
)
yield article.load_item()
record-high-after-sensex-breaches-80000-mark -9431868/
Код: Выделить всё
"article_text",
'//div[@id="pcl-full-content"]/p/text() | //div[contains(@class,"ie-premium-content-block")]/p/text()',
)
Раньше я использовал это как свой XPath.
Раньше я использовал это как свой XPath. p>
выход:
Код: Выделить всё
- AssertionError: assert [+ received] == [- snapshot]
list([
dict({
- snapshot 'article_text': 'IT stocks led Indian shares to open higher on Thursday, in line with Asian peers, after softer US data boosted hopes for a rate cut in September. The NSE Nifty 50 was up 0.27% at 24,354.1 points, while the S&P BSE Sensex added 0.29% to 80,214.56 points, hitting record highs, as of 9:26 a.m. IST. Asian shares rose on renewed bets that the may start cutting rates in September following soft labour data in the world’s largest economy. Nine of the 13 major sectors in India logged gains. US rate-sensitive IT stocks rose 1%. Non-bank lender L&T Finance rose about 3% after strong loan growth and disbursal numbers in the June quarter. Real estate developer Brigade Enterprises rose 4% after signing a joint development deal for a residential project in Bengaluru, with a gross development value of 11 billion rupees.',
+ received 'article_text': 'IT stocks led Indian shares to open higher on Thursday, in line with Asian peers, after softer US data boosted hopes for a rate cut in September. The was up 0.27% at 24,354.1 points, while the S&P added 0.29% to 80,214.56 points, hitting record highs, as of 9:26 a.m. IST. Asian shares rose on renewed bets that the may start cutting rates in September following soft labour data in the world’s largest economy. Nine of the 13 major sectors in India logged gains. US rate-sensitive IT stocks rose 1%. Non-bank lender L&T Finance rose about 3% after strong loan growth and disbursal numbers in the June quarter. Real estate developer Brigade Enterprises rose 4% after signing a joint development deal for a residential project in Bengaluru, with a gross development value of 11 billion rupees.',
'author': 'Reuters',
...
])
Моя реальная проблема заключается в том, что мне нужно получить весь текст из соответствующего элемента div, но если я изменю паука, выходные данные не изменятся
Подробнее здесь: https://stackoverflow.com/questions/790 ... h-is-empty