简体   繁体   English

如何使用 scrapy 在两个不同字符之间提取 URL 的一部分

[英]How to extract part of URL between two different characters with scrapy

I have url that has a following structure:我有 url 具有以下结构:

https://example.com/string?rest

I am trying to extract only the 'string' part and so far I can only think of using我试图只提取“字符串”部分,到目前为止我只能想到使用

response.url.split('/')[3]

to extract everything after third '/' Is it possible to extract the part after third '/' and before the '?'在第三个“/”之后提取所有内容是否可以在第三个“/”之后和“?”之前提取部分? sign?符号?

Might be able to use something in urllib.parse :可能可以在urllib.parse中使用一些东西:

from urllib.parse import urlparse
print(urlparse(response.url).path.split('/')[-1])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM