【发布时间】:2020-08-14 02:16:33
【问题描述】:
有什么方法可以抓取 URL 中的每个页面?
如https://gogo.mn/在网址中查找每篇文章页面?
以下是我目前所拥有的
import urllib
import urlparse
import re
from bs4 import BeautifulSoup
url = "https://gogo.mn/"
urls = []
soup = BeautifulSoup(urllib.urlopen(url).read())
for tag in soup.findAll('a',href=True):
tag['href'] = urlparse.urljoin(url,tag['href'])
if url in tag['href'] and tag['href'] not in visited:
urls.append(tag['href'])
由于某种原因,此代码不会爬过所有页面。我如何做到这一点?
【问题讨论】:
-
你需要从网站的特定部分获取链接并抓取,否则它将是一个无限循环
标签: python python-3.x beautifulsoup