我想将网址添加到我收到的链接中。我怎样才能做到这一点? 我的源代码是这样的
</a></li><li><a href="/archive/2017-06-13">
Link title 2017-06-13
</a></li><li><a href="/archive/2017-06-12">
Link title 2017-06-12
</a></li><li><a href="/archive/2017-06-11">
我的python 3代码
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from bs4 import BeautifulSoup
import urllib.request
url = "https://myurl.com"
parseurl = "https://myurl.com/archivelist"
url_readd = urllib.request.urlopen(parseurl)
soup = BeautifulSoup(url_readd, 'html.parser')
project_href = [i['href'] for i in soup.find_all('a', href=True) if i['href'] != "#"]
for string in project_href:
print(append url(string))
答案 0 :(得分:0)
您正在寻找字符串连接(甚至可能是字符串格式化),有几种可能性:
for string in project_href:
print(url + string)
print("".join([url, string]))
print("{}{}".format(url, string))
print("%s%s" % (url, string))