Scraping multiple paginated links with BeautifulSoup and Requests

前端 未结 1 592
再見小時候
再見小時候 2021-02-06 17:39

Python Beginner here. I\'m trying to scrape all products from one category on dabs.com. I\'ve managed to scrape all products on a given page, but I\'m having trouble iterating o

相关标签:
1条回答
  • 2021-02-06 18:33

    Their next page button has a title of "Next" you could do something like:

    import requests
    from bs4 import BeautifulSoup as bs
    
    url = 'www.dabs.com/category/computing/11001/'
    base_url = 'http://www.dabs.com'
    
    r = requests.get(url)
    
    soup = bs(r.text)
    elm = soup.find('a', {'title': 'Next'})
    
    next_page_link = base_url + elm['href']
    

    Hope that helps.

    0 讨论(0)
提交回复
热议问题