Python 机械化、urllib、美化集团;相对路径
mechanize、urllib或beautifulsoup是否有任何内置方法来处理混合使用绝对URL和相对URL的网站爬网 一个解决方案是有很多例外Python 机械化、urllib、美化集团;相对路径,python,web-crawler,beautifulsoup,mechanize,urllib2,Python,Web Crawler,Beautifulsoup,Mechanize,Urllib2,mechanize、urllib或beautifulsoup是否有任何内置方法来处理混合使用绝对URL和相对URL的网站爬网 一个解决方案是有很多例外 'http://' + 'www.stackoverflow.com' 'http://www.stackoverflow.com' + '/questions/ask' 有更好的选择吗?记录在案,这是我的解决方案:) domain = re.search('(http:\/\/.*\.\D+?|https:\/\/.*\.\D+?)\/',u
'http://' + 'www.stackoverflow.com'
'http://www.stackoverflow.com' + '/questions/ask'
有更好的选择吗?记录在案,这是我的解决方案:)
domain = re.search('(http:\/\/.*\.\D+?|https:\/\/.*\.\D+?)\/',url.strip()).group(1)
if re.search('mailto',url.strip()) != None:
pass
elif re.search('(http:\/\/.*\.\D+?|https:\/\/.*\.\D+?)\/',url.strip()) != None:
u = url.strip().encode('utf8')
elif re.search('^/',url.strip()) != None:
u = domain+url.strip().encode('utf8')
else:
u = domain+'/'+url.strip().encode('utf8')