函数get("href")
没有返回完整链接。在html文件中存在以下链接:
但是,函数link.get("href")
返回:
"navhome.php?lightbox&dpxshig=/iprop_prod=180-slim/tipo=fotolivro/width=950/height=615/control=true/tema=tema_02/nome_tema=Q2wmYWFjdXRlO3NzaWNvIFByZXRv&cpmdsc=MOZAO"
sub_site = "https://www.fotoregistro.com.br/navhome.php?vitrine-produto-slim"
response = urllib.request.urlopen(sub_site)
data = response.read()
soup = BeautifulSoup(data,'lxml')
for link in soup.find_all('a'):
url = link.get("href")
print (url)
使用select,看起来打印效果很好
使用
所有链接
让我把重点放在html中问题的具体部分:
您可以通过以下操作获得:
你发现
url
是:在字符串的开头可以看到两个重要的模式:
//
这是保持当前协议的一种方法,参见this李>\r
这是ASCII回车(CR)李>当您打印它时,您只需丢失以下部分:
如果需要原始字符串,可以在} :
for
循环中使用^{你会得到:
如果需要路径,可以替换初始零件:
你会得到:
不指定类:
相关问题 更多 >
编程相关推荐