tbody問題:
在爬去某些網站一些信息的時候,xpath工具上顯示類容是正確的,但是在scrapy代碼中一直返回空列表
Scrapy的部分代碼:
class LotteryspiderSpider(scrapy.Spider):
#爬蟲名字
name = 'LotterySpider'
#允許的域名
allowed_domains = ['www.lottery.gov.cn']
#入口URL,扔到調度器
start_urls = ['http://www.lottery.gov.cn']
def parse(self, response):
print(response.text)
lottery_list = response.xpath('//div[@class="b11_06"]//tbody')
網頁上顯示:

爬到本地全部類容中 //div[@class="b11_06"]少了tbody
<div class="b11_06"> <table border="0" cellpadding="0" cellspacing="0"> <tr><td width="45" style="background:#ECECEC; line-height:30px; height:24px;">玩法</td>
經查詢得知原因是:瀏覽器會對html文本進行一定的規范化,所以會自動在路徑中加入tbody,導致讀取失敗,在此處直接在路徑中去除tbody即可。
