Python 3.x 有没有办法更新以';开头的url/';用蟒蛇和靓汤
以下是我面临的问题锚定标记href以/abcd.html开始 我想将其更新为href=”https://www.example.com/abcd.html“在美化组实例本身中Python 3.x 有没有办法更新以';开头的url/';用蟒蛇和靓汤,python-3.x,beautifulsoup,Python 3.x,Beautifulsoup,以下是我面临的问题锚定标记href以/abcd.html开始 我想将其更新为href=”https://www.example.com/abcd.html“在美化组实例本身中 这是否可能?更改的href参数 ''' soup=BeautifulSoup(txt,'html.parser') #查找链接, from bs4 import BeautifulSoup txt = ''' <html> <a href="/abcd.html" title="link">So
这是否可能?更改
的href
参数
'''
soup=BeautifulSoup(txt,'html.parser')
#查找链接,
from bs4 import BeautifulSoup
txt = '''
<html>
<a href="/abcd.html" title="link">Some link</a>
</html>
'''
soup = BeautifulSoup(txt, 'html.parser')
# find link, <a> tag
link = soup.find('a')
# change href attribute in <a>
link['href'] = 'https://www.example.com' + link['href']
# print soup
print(soup.prettify())
<html>
<a href="https://www.example.com/abcd.html" title="link">
Some link
</a>
</html>