(r“““<div style=“background: url(‘(.*?)‘) no-repeat; background-size: auto 100%;“/>“““

 <div style="background:url('//cdnimg01.kurogame.com/M00/1A/80/ChpCl2EBM7iEDAu3AAAAAGIgNAU818.jpg') no-repeat; background-size: auto 100%;"/>

当用pyquery爬取图片时,有时候会遇到上面这样,没有直接说明长度宽度,而且url也不好直接拿出来。

这时可以用正则表达式re 的findall把上面用迭代器得到的url里 需要的字符串提取出来。

开始我是按下面提取的

imurl = re.findall(r"""<div style="background: url('(.*?)') no-repeat; background-size: auto 100%;"/>""", imurl)

print一下

不知道什么情况,然后发现我所需要的url在单引号里面,这样提取里面的信息就只需要r'\'(.*)\''修改如下

imurl = re.findall(r'\'(.*)\'', imurl)[0]

print一下,可以了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
const ViewRender = memo((props: ViewProps) => { const { pointData, pageData, width, dragStop, onDragStart, onResizeStop, preview } = props; const FixedData: Array<PointDataItem> = pointData.filter(e => e.item.type == 'Fixed') const nFixedData: Array<PointDataItem> = pointData.filter(e => e.item.type != 'Fixed') return ( (!preview ? ( <GridLayout cols={24} rowHeight={2} margin={[0, 0]} width={width} // @ts-expect-error onDragStop={debounce(dragStop, 500)} onDragStart={onDragStart} onResizeStop={onResizeStop} style={{ minHeight: '100vh', backgroundSize: '100%', backgroundRepeat: 'no-repeat', backgroundColor: pageData && pageData.bgColor, backgroundImage: pageData && pageData.bgImage ? `url(${pageData.bgImage[0].url})` : 'initial' }} > {pointData.map((value: PointDataItem) => ( <div key={value.id} data-grid={value.point} className={onDragStart && styles.dragItem} style={{ overflow: value.item.type == 'Fixed' ? 'visible' : 'hidden' }}> {value.item.type == 'Fixed' ? ( <div style={{ transform: `translateY(-${value.item.config.y}px)` }}> <DynamicEngine {...(value.item as any)} isTpl={false} /> </div> ) : ( <DynamicEngine {...(value.item as any)} isTpl={false} /> )} </div> ))} </GridLayout> ) : ( <> <GridLayout cols={24} rowHeight={2} margin={[0, 0]} width={width} style={{ minHeight: '100vh', backgroundSize: '100%', backgroundRepeat: 'no-repeat', backgroundColor: pageData && pageData.bgColor, backgroundImage: pageData && pageData.bgImage ? `url(${pageData.bgImage[0].url})` : 'initial' }}> {nFixedData.map((value: PointDataItem) => ( <div key={value.id} data-grid={value.point}> <DynamicEngine {...(value.item as any)} isTpl={false} /> </div> ))} </GridLayout> {FixedData.map((value: PointDataItem) => ( <div key={value.id} data-grid={value.point}> <DynamicEngine {...(value.item as any)} isTpl={false} /> </div> ))} </> )) ) })帮我优化这段代码
最新发布
06-06

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值