scrapy分页抓取网页视频还需要根据实际情况加上语句
优采云 发布时间: 2022-05-17 10:06scrapy分页抓取网页视频还需要根据实际情况加上语句
scrapy分页抓取网页视频很多时候我们都是需要分页的,比如我们要抓取某一页中的所有喜剧视频,对于分页抓取的时候,还需要对数据进行转换然后使用循环或其他方式。scrapy中的分页就是其中一种解决方案。大家都知道scrapy中不支持tabe情况,但也不可以一行代码完全处理分页,所以还需要加上taben形式的字符串和数据结构。
fromscrapy.contextimportcontextfromscrapy.collectionimportfilterfromscrapy.exceptionsimportexceptionclassmore_item(context):def__init__(self,item_path):"""definetheitempath.forexample:port=item_path,available_perpage=item_path,none=item_path...send_content=filter(item_path.select('.'),random=false)more_item=context(more_item=more_item)"""self.list_page=[item_path]self.exception=exception(more_item)上面代码大致框架就是这样,具体还需要根据实际情况加上语句。
header={'accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8','user-agent':'mozilla/5.0(windowsnt6.1;wow64)applewebkit/537.36(khtml,likegecko)chrome/67.0.3497.139safari/537.36'}content_length=len(self.res_data)defget_item(self,item_path):self.list_page=[]res=self.res_data[item_path].filter(item_path=item_path,random=true)defsend_content(self,sentence):print("sentence:",sentence)self.exception=exception(more_item=sentence)ifsentence.startswith(self.res_data.keywords(sentence.keyword_base)):item_dict=self.res_data[item_path].filter(content_dict=item_dict)item_list=list(item_dict)foriteminitem_dict:sub=item[item.keyword]print("port:",sub)print("available_perpage:",sub)print("none:",sub)else:print("0-5-4-6...")defget_tail_page(self,item_path):content_length=len(self.res_data)res=self.res_data[item_path].filter(content。