且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

AttributeError: 'str' 对象没有属性 'xpath'

更新时间:2023-12-02 23:13:46

试试这个:

import scrapy
class CybexbotSpider(scrapy.Spider): 
   name = 'cybexbot'
   allowed_domains = ['http://links.com']
   start_urls = ['http://links.com']
   def parse(self, response):
       data=response.xpath('//tr[contains(@class,"GridView")]')
       for d in data[1:]:
         print(type(d))
         temp=dict()
         temp['Code']=d.xpath('tr//td[1]/a/text()').extract()
         temp['Desc']=d.xpath('tr//td[2]/a/text()').extract()
         yield temp

一旦你提取它,它就会变成一个字符串,所以图书馆不能再处理它

Once you extract it, it becomes a string so the library can no longer process it