这是一个创建于 2021 天前的主题,其中的信息可能已经有所发展或是发生改变。
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)
第 1 条附言 · 2018-12-03 16:44:20 +08:00
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)
第 2 条附言 · 2018-12-03 16:45:50 +08:00
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)
8 条回复 • 2018-12-03 16:48:30 +08:00
![kimchan](https://cdn.v2ex.com/avatar/acac/4019/53281_normal.png?m=1517191970) |
|
1
kimchan 2018-12-03 16:15:22 +08:00
这... 没法看啊..
|
![whoami9894](https://cdn.v2ex.com/avatar/98db/b7ad/282705_normal.png?m=1583073579) |
|
2
whoami9894 2018-12-03 16:16:49 +08:00 via Android
楼下有人能理解楼主想表达啥吗
|
![holajamc](https://cdn.v2ex.com/avatar/65ea/4316/137459_normal.png?m=1536633520) |
|
3
holajamc 2018-12-03 16:19:06 +08:00
if not apple_touch_url and response.xpath('//link[contains(@rel,"icon")]/@href'): 猜的)
|
![kimchan](https://cdn.v2ex.com/avatar/acac/4019/53281_normal.png?m=1517191970) |
|
4
kimchan 2018-12-03 16:25:47 +08:00
我猜是他需要在最上边加一句: apple_touch_url = None
|
![ant2017](https://cdn.v2ex.com/avatar/d1f7/ca2d/236015_normal.png?m=1540734619) |
|
5
ant2017 2018-12-03 16:27:00 +08:00
我猜是判断变量是否定义? 'apple_touch_url' in dir()
|
![Ewig](https://cdn.v2ex.com/gravatar/4f00a030a1532d147ba8ec51ef52ad26?s=48&d=retro) |
|
6
Ewig 2018-12-03 16:46:23 +08:00
|
![Trim21](https://cdn.v2ex.com/avatar/6b4d/8caf/128017_normal.png?m=1651064440) |
|
7
Trim21 2018-12-03 16:47:44 +08:00
用 markdown 语法
|