Python 爬淘宝网

# -*- coding:utf-8 -*-
import requests
import Debug
from bs4 import BeautifulSoup
import re


class VisitWeb(object):
    def __init__(self):
        self.session = requests.session()
        self.soup = None

    def visit(self, url):
        r = self.session.get(url)
        self.soup = BeautifulSoup(r.text, 'lxml')

    def find_all(self, name):
        links = self.soup.findAll(name)
        for i in range(0, len(links) - 1):
            s = str(links[i])

            regex_str = ".*?([\u4E00-\u9FA5])"
            match_obj = re.findall(regex_str, s)
            name = ''.join(match_obj)

            if s.find('href') != -1:
                temp = str(links[i]['href'])
                if temp.find("taobao") != -1:
                    Debug.print_debug_info(str(i) + ": " + name + " " + links[i]['href'])


if __name__ == '__main__':
    visit = VisitWeb()
    url = 'https://www.taobao.com/'
    visit.visit(url)
    visit.find_all('a')
发布了156 篇原创文章 · 获赞 32 · 访问量 43万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览