def parse(self, response, *args):
item = TuiqiuspiderproItem()
resp = response.json()
for article in resp['articles']:
if compTime(article['published_at']) and article['channel'] != "mini_top" and article['is_video'] is False:
item['publish_time'] = article['published_at']
item['tag'] = resp['label']
item['source_href'] = article['share']
item['source'] = "——"
data = scrapy.Request(url=article['share'], callback=self._article, meta={'item': item})
data.meta['item'] = item
yied data
def _article(self, response):
item = response.meta['item']
soup = BeautifulSoup(response.text, 'lxml')
comments = soup.findAll(text=lambda text: isinstance(text, Comment))
[comment.extract() for comment in comments]
try:
article = soup.find("div", {"class": "news-left"})
tips = article.find('p', {"class": "tips"}).find_all('span')
if tips and len(tips) > 1:
item['author'] = tips[1].get_text()
else:
item['author'] = tips[0].get_text()
except Exception as e:
pass
author = response.xpath('.//div[@class="news-left"]/p[@class="tips"]/span/text()').extract_first()
item['author'] = author
item['content'] = response.xpath('.//div[@class="con"]').extract_first()
yield item
scrapy pase调用自定义函数每次每次遍历得到的数据都是一样的,只有自定义中的数据是不一样的
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- @吃瓜群众研究中心 2021-04-22 11:12关注
pase 中的item每次遍历都是一样的,只有_articel中的item是数据是一样的,怎么解决每次遍历返回的数据
解决 无用评论 打赏 举报
悬赏问题
- ¥50 微信聊天记录备份到电脑提示成功了,但还是没同步到电脑微信
- ¥15 python怎么在已有视频文件后添加新帧
- ¥20 虚幻UE引擎如何让多个同一个蓝图的NPC执行一样的动画,
- ¥15 fluent里模拟降膜反应的UDF编写
- ¥15 MYSQL 多表拼接link
- ¥15 关于某款2.13寸墨水屏的问题
- ¥15 obsidian的中文层级自动编号
- ¥15 同一个网口一个电脑连接有网,另一个电脑连接没网
- ¥15 神经网络模型一直不能上GPU
- ¥20 wpf datagrid单元闪烁效果失灵