python3 - 添加链接导入网址



我想将网址添加到我收到的链接中。我该怎么做?我的源代码是这样的

</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">

还有我的蟒蛇 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))

您正在寻找字符串连接(甚至可能是字符串格式(,有几种可能性:

for string in project_href:
    print(url + string)
    print("".join([url, string]))
    print("{}{}".format(url, string))
    print("%s%s" % (url, string))

最新更新