0
有沒有一種方法可以統計BeautifulSoup中爬行的結果數量?Python BeautifulSoup:有沒有一種方法來計算爬網結果的數量?
這是代碼。
def crawl_first_url(max_page):
page = 1
while page <= max_page:
url = 'http://www.hdwallpapers.in/page/' + str(page)
source_code = requests.get(url)
plain_text = source_code.text
soup = BeautifulSoup(plain_text, 'html.parser')
for div in soup.select('.thumb a'):
href = 'http://www.hdwallpapers.in' + div.get('href')
crawl_second_url(href)
page += 1
def crawl_second_url(second_href):
#need to count the number of results here.
#I tried, len(second_href) but it doesn't work well.
crawl_first_url(1)
我想第二個函數來計算抓取結果的數量,例如,如果19個URL已經被抓取,我想要它的數量。
'crawl_second_url'做什麼?它只計算結果嗎? – dstudeba
@dstudeba是的,它應該只計算結果的數量,但我不知道我該怎麼做... – Lindow