html代码中的零碎项结果

2024-10-01 15:40:15 发布

您现在位置:Python中文网/ 问答频道 /正文

有没有可能在html代码中插入一个刮下的项目的结果?我如何实现它

像这样:

for ntp in response.css('div.content-1col-nobox'):
description = ntp.xpath('normalize-space(//div[6]/div[1]/div[2]/div/blockquote[2]/p/text())').extract_first()
'Description': '<html><body>......'description'..............</body></html>',\

先谢谢你


Tags: 项目代码indivforresponsehtmlbody
1条回答
网友
1楼 · 发布于 2024-10-01 15:40:15

您可以使用简单的字符串操作。 1.'%d' % (description)

  1. '<html>{} some more html </html>'.format(description)

您需要使用字符串格式的描述变量。 我想str(描述)会有用的

description = ntp.xpath('normalize-space(//div[6]/div[1]/div[2]/div/blockquote[2]/p/text())').extract_first()

'Description': '<html><body>...... {} ..............</body></html>'.format(str(descripion))

正如注释中所建议的,您可以使用python REhttps://docs.python.org/3/library/re.html

相关问题 更多 >

    热门问题