scrapy筆記(2)爬天天美劇首頁

昨天初學了下scrapy,今天測試下效果,看見網上很多都是用豆瓣的頁面做測試,那么久換個不一樣的,就選擇 天天美劇 了

#coding:utf-8
import json
import scrapy
from my_scrapy_project.items import DmozItem
class DmozSpider(scrapy.Spider):
    name = "dmoz"
    allowed_domains = ["ttmeiju.com"]
    start_urls = [
    "http://www.ttmeiju.com/"
    ]

def parse(self, response):
    for sel in response.xpath("http://table[contains(@class,'seedtable')]/tr[contains(@class,'Scontent')]"):
        item = DmozItem()
        title = sel.xpath('td[2]/a/text()').extract()[0]
        link = sel.xpath('td[2]/a/@href').extract()
        download = sel.xpath('td[3]/a/@href').extract()
        item['title'] = title
        item['link'] = link
        item['download'] = download
        yield item
  • response.xpath("http://table[contains(@class,'seedtable')]/tr[contains(@class,'Scontent')]") 這段選擇了天天美劇首頁新的資源板塊,意思是選擇class為seedtable的table里面class為scontent的tr
  • sel.xpath('td[2]/a/text()').extract()[0] 選擇的是片源的名字,通過審查元素,查看源代碼可以看到
  • sel.xpath('td[3]/a/@href').extract() 這是資源的各種下載鏈接

輸出結果:

{"download": ["http://pan.baidu.com/s/1i3CcdQd"], "link": ["http://www.ttmeiju.com/seed/38897.html"], "title": "\n\u840c\u5ba0\u4e5f\u75af\u72c2 Pets Wild at Heart S01E02 HR-HDTV \u5927\u5bb6\u5b57\u5e55\u7ec4                    \n                    \n                    "},
{"download": ["http://pan.baidu.com/s/1c0rT2pi"], "link": ["http://www.ttmeiju.com/seed/38896.html"], "title": "\n\u840c\u5ba0\u4e5f\u75af\u72c2 Pet Wild at Heart S01E01 HR-HDTV \u5927\u5bb6\u5b57\u5e55\u7ec4                    \n                    \n                    "},
{"download": ["http://pan.baidu.com/s/1qWp3jgo"], "link": ["http://www.ttmeiju.com/seed/38895.html"], "title": "\n\u840c\u5ba0\u4e5f\u75af\u72c2 Pet Wild At Heart S01E01 \u5927\u5bb6\u5b57\u5e55\u7ec4                    \n                    \n                    "},
{"download": ["http://pan.baidu.com/s/1bnxvmFl"], "link": ["http://www.ttmeiju.com/seed/38894.html"], "title": "\n\u7231\u306e\u65c5\u9986 The Love Hotel \u5927\u5bb6\u5b57\u5e55\u7ec4                    \n                    \n                    "},

又出現中文字符編碼問題 。。。。 明天解決

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容