Python 中的一个逻辑写法

2018-12-03 16:01:58 +08:00
 Ewig
if response.xpath('//link[contains(@rel,"apple-touch-icon-precomposed")]/@href') :
apple_touch_url = response.xpath('//link[contains(@rel,"apple-touch-icon-precomposed")]/@href').extract()
apple_touch_url=[link for link in apple_touch_url if 'https' in link or 'http' in link ]
item['logo'] = apple_touch_url
if not apple_touch_url:
‘这里没有这个列表我想走 elif 的逻辑’但是好像没有这样的语法,求人指教,谢谢

elif response.xpath('//link[contains(@rel,"icon")]/@href'):
rel_url=response.xpath('//link[contains(@rel,"icon")]/@href').extract()
item['logo']=rel_url
print(rel_url)
1360 次点击
所在节点    问与答
8 条回复
kimchan
2018-12-03 16:15:22 +08:00
这... 没法看啊..
whoami9894
2018-12-03 16:16:49 +08:00
楼下有人能理解楼主想表达啥吗
holajamc
2018-12-03 16:19:06 +08:00
if not apple_touch_url and response.xpath('//link[contains(@rel,"icon")]/@href'):
猜的)
kimchan
2018-12-03 16:25:47 +08:00
我猜是他需要在最上边加一句: apple_touch_url = None
ant2017
2018-12-03 16:27:00 +08:00
我猜是判断变量是否定义?
'apple_touch_url' in dir()
Ewig
2018-12-03 16:46:23 +08:00
@kimchan 我不知道怎么排版
Trim21
2018-12-03 16:47:44 +08:00
用 markdown 语法
hahastudio
2018-12-03 16:48:30 +08:00
@Ewig 贴 gist link 到评论里
https://gist.github.com/

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/513852

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX