python mongodb爬取58网站

时间:2022-05-08
本文章向大家介绍python mongodb爬取58网站,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
__author__ = 'Lee'

from bs4 import BeautifulSoup
import requests
'''
用这个爬取58中二手的分栏

'''
start_url = 'http://bj.58.com/sale.shtml' #开始的页面
url_host = 'http://bj.58.com'

def get_channel_urls(url):
    wb_data = requests.get(url)
    soup = BeautifulSoup(wb_data.text,'lxml')
    links = soup.select('ul.ym-submnu > li > b > a')
    for link in links:
       page_url = url_host + link.get('href')
       print(page_url)