アウトライン
コンセプト:モニタリング
コア技術:重複排除
使用インクリメンタルサイトに適して:
- 深さに基づくクロール
- クロールページのURLを記録するために(記録用紙)
- 非クロールの深さに基づいて、
- レコードテーブル:データに対応した指紋データによるクロール
- 元のデータの一意の識別のセット:指紋データ
- データ - >データの指紋 - >データベースクエリ
- hashlib
どのようにテーブルのいわゆるレコードは何の形で存在しているのですか?
例
4567映画のネットワーク名とサイトは、データの増加をクロール更新されたフィルム、を紹介してクロール。
- 住所:
https://www.4567tv.tv/frim/index1.html
- この実施形態は、クロールの深さに基づいています。
scrapy startproject zlsPro
scrapy genspider zls www.xxx.com
①
- マニュアル奥行きパラメータの受渡しクロール
- 使用
self.conn.sadd('movie_url', detail_url)
かクロール膜を介して決定するために、戻り値。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
インポート scrapy から zlsPro.items インポート ZlsproItemを からのRedis インポート Redisの
クラス ZlsSpider (scrapy.Spiderを): NAME = 'ZLS' start_urls = [ 'https://www.4567tv.tv/frim/index1.html' ] CONN = Redisの('127.0.0.1' 、6379)DEF 構文解析(自己、応答): li_list = response.xpath('/ HTML /本体/ DIV [1] / DIV / DIV / DIV / DIV [2] / UL /リチウム')用のLi
中 li_list: = li.xpathタイトル('./div/div/h4/a/text()').extract_first() detail_url = 'https://www.4567tv.tv' + li.xpath(」./ DIV / DIV / H4 / A / HREF @ ').extract_first() RET = self.conn.sadd(' movie_url "、detail_url)IF RET: パフォーマーli.xpath =('./div/div/p/text()').extract_first() 項目= ZlsproItem() 項目[ '表題' ] =タイトル 項目[ '演奏' ] =演奏収率
scrapy.Request(detail_url、コールバック= self.parse_detail、メタ= { 'アイテム':アイテム})他: プリント('暂无更新的数据')DEF parse_detail (自己、応答): アイテム= response.meta [ 「アイテム' ] コンテンツ= response.xpath('//のdiv [@クラス= "のStuI-content__detail"] / P /スパン[クラス@ = "詳細内容"] /テキスト()').extract_first() 項目[ 'コンテンツ' ] =コンテンツ収率アイテム
|
②
1 2 3 4 5 6 7 8 |
輸入 scrapyの
クラス ZlsproItem (scrapy.Item) :# タイトル= scrapy.Field() パフォーマー= scrapy.Field() コンテンツ= scrapy.Field()
|
③
1 2 3 4 5 6 7 8 9 10 |
class ZlsproPipeline(object):
def process_item(self, item, spider): title = item['title'] performer = item['performer'] content = item['content'] conn = spider.conn conn.lpush('movie', item) return item |