如何获得网站的标题?

2024-05-23 23:13:34 发布

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

我有这个链接: http://dx.doi.org/10.1109/mper.1991.88667

如何用python获取它的头并在其中找到arnumber=88667? 意思是:只得到http://ieeexplore.ieee.org/xpl/articleDetails.jsp?arnumber=88667 (而不是整个网站或其他) 然后找到arnumber=88667。你知道吗

非常感谢。你知道吗


Tags: orghttp网站链接doiieeedxxpl
3条回答

另一种选择(无请求或机械化):

import urllib2

url_path = "http://dx.doi.org/10.1109/mper.1991.88667"
urllib2.urlparse.parse_qs(urllib2.urlopen(url_path).url)["arnumber"][0]
>>> '88667'
pip install requests

import requests
from urlparse import parse_qs, urlsplit

r = requests.get("http://dx.doi.org/10.1109/mper.1991.88667")
url = r.url
get_parameter = parse_qs(urlsplit(url).query)['arnumber'][0]

更多信息可以在requests documentationurlparse documentation中找到。你知道吗

您可以使用requestsurlparse库:

import requests
from urlparse import parse_qs, urlsplit

r = requests.get('http://dx.doi.org/10.1109/mper.1991.88667')
print parse_qs(urlsplit(r.url).query)['arnumber'][0]

尽管看起来你可以:

print 'http://dx.doi.org/10.1109/mper.1991.88667'.rpartition('.')[2]

相关问题 更多 >