亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我想在我的代碼中獲取 URL,而不是 True 或 False

我想在我的代碼中獲取 URL,而不是 True 或 False

HUWWW 2021-10-26 18:16:17
我想獲得的URL列表,而不是一個True的False在聲明的最后答復。#!/usr/bin/env pythonimport requestsfrom BeautifulSoup import BeautifulSoupurl ="https://www.geant.tn/"response = requests.get(url)# parse htmlpage = str(BeautifulSoup(response.content))def getURL(page):這部分沒問題    """    :param page: html of web page (here: Python home page)    :return: urls in that page    """    start_link = page.find("a href")    if start_link == -1:        return None, 0    start_quote = page.find('"', start_link)    end_quote = page.find('"', start_quote + 1)    url = page[start_quote + 1: end_quote]    return url, end_quotewhile True:    url, n = getURL(page)    page = page[n:]我在這里遇到問題,因為我得到True或False顯示:if url.endswith('.html'):    print urlelse:    break如果你能幫助我,非常感謝!
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 197 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號