Scrapy 我如何混合两种类型的刮痧
我有一个div,它既包含Scrapy 我如何混合两种类型的刮痧,scrapy,Scrapy,我有一个div,它既包含,也包含。 它们没有类或ID,所以我需要迭代它们,并根据内容激活一些逻辑 如果我只有,那很容易: entry_content = sel.xpath('//div[contains(@class, "entry-content")]') all_p = entry_content.xpath(('.//p//text()')).extract() for p in all_p: #do some logic according
,也包含
。
它们没有类或ID,所以我需要迭代它们,并根据内容激活一些逻辑
如果我只有
,那很容易:
entry_content = sel.xpath('//div[contains(@class, "entry-content")]')
all_p = entry_content.xpath(('.//p//text()')).extract()
for p in all_p:
#do some logic according to content
问题是在那些
中隐藏了一个
(一个或多个)和
我怎样才能把他们列成“联合名单”?所以,不要:
entry_content.xpath('.//p//text()')
您可以使用XPath,如:
entry_content.xpath('.//*[name()="p" or name()="ul"]//text()')
阅读更多: