1
我試圖通過遞歸調用all_pages函數來獲取網站的所有獨特url,但是這個函數並沒有給出網站的所有url。如何使用beautifulsoup來取消整個網站
我想要做的就是使用BeautifulSoup獲取網站的所有獨特的網址。我的代碼如下所示:
base_url = "http://www.readings.com.pk/"
unique_urls=[]
def all_pages(base_url,unique_urls=[]):
response = requests.get(base_url)
soup = BeautifulSoup(response.content, "html.parser")
for link in soup.find_all("a"):
url = link["href"]
absolute_url = urljoin(base_url, url)
if absolute_url not in unique_urls:
if base_url in absolute_url:
unique_urls.append(absolute_url)
print (absolute_url)
all_pages(absolute_url,unique_urls,book_urls)
all_pages(base_url,unique_urls)
歡迎賽義德。我看到你有你的代碼作爲圖像。我強烈建議您將它作爲文本放置,並在編輯器中使用{}標記爲代碼片段。人們會更能夠幫助你。請閱讀[如何問](http://stackoverflow.com/help/how-to-ask)。 – micstr