Home > other >  Python scrapy framework about xpath returns null
Python scrapy framework about xpath returns null

Time:09-28

I'm Google plug-in tried all these xpath yes ah why always print out I write in accordance with the following words can't directly display, if only to print the title, I only show an empty list, I was really hard, really good hard ah, self-study/(ㄒ o ㄒ)/~ ~
As shown in figure

 


# - * - coding: utf-8 - * -
The import scrapy


The class TiebaPaSpider (scrapy. Spiders) :
Name='tieba_pa'
Allowed_domains=[' tieba.com ']
Start_urls=[' https://tieba.baidu.com/f?ie=utf-8&kw=lol ']

Def parse (self, response) :
Tieba_data=https://bbs.csdn.net/topics/response.xpath ("//ul [contains (@ id, 'thread_list)]/li ")

For tieba_l tieba_data in:
Title=tieba_l. Xpath (".//a [contains (@ class, 'j_th_tit)]/text () ")
The content=tieba_l. Xpath (".//div [contains (@ class, 'threadlist_abs threadlist_abs_onlyline')]/text () ")
Time=tieba_l. Xpath (".//span [@ title='reply last time']/text () ")
Print ("="* 20)
Print (title [0])
Print (content [0])
Print (time [0])
Print ("="* 20)
# tieba_data=https://bbs.csdn.net/topics/response.body
# print (tieba_data)
  • Related