爱玺玺

爱玺玺的生活日记本。wx:lb87626

python xpath获取当前节点属性

import scrapy

from bs4 import BeautifulSoup as bs


class MyspiderSpider(scrapy.Spider):

    name = 'myspider'

    allowed_domains = ['janpn.com']

    start_urls = ['http://www.janpn.com/xuanhuanqihuan/list-1-1.html']


    def parse(self, response):

        #with open("jpan.html","wb") as f:

        # f.write(response.body)

        source_list=response.xpath('//a[@class="shop"]')


        for item in source_list:

        print(item.xpath('./@title')[0].extract())

        print(item.xpath('./@href')[0].extract())

        


发表评论:

Powered By Z-BlogPHP 1.4 Deeplue Build 150101

Copyright Your WebSite.Some Rights Reserved.

蜀ICP备11021721号-5