안녕하세요, 친구들과XPath/Scrap scrape DOCTYPE
저는 Scrapy와 XPath를 사용하여 스크레이퍼를 만들고 있습니다. 내가 긁어 모으는 데 관심이있는 것은 내가 가로 지르는 모든 사이트의 DOCTYPE이며 이것에 관한 문서를 찾는 데 어려움을 겪고 있으며 상대적으로 간단한 요청이기 때문에 가능해야한다고 생각합니다. 어떤 제안? ,
import scrapy
from scrapy.selector import HtmlXPathSelector
from scrapy.http import HtmlResponse
from tutorial.items import DanishItem
from scrapy.http import Request
import csv
class DanishSpider(scrapy.Spider):
name = "dmoz"
allowed_domains = []
start_urls = [very long list of websites]
def parse(self, response):
for sel in response.xpath(???):
item = DanishItem()
item['website'] = response
item['DOCTYPE'] = sel.xpath('????').extract()
yield item
새로운 거미 DOCTYPE을 검색하지만, 어떤 이유로 지정된 .json 내 반응을 인쇄합니다 :
건배, 여기
조이는 지금까지이 그 코드입니다 파일을 한 번만 사용하지 않고 15 번
class DanishSpider(scrapy.Spider):
name = "dmoz"
allowed_domains = []
start_urls = ["http://wwww.example.com"]
def parse(self, response):
for sel in response.selector._root.getroottree().docinfo.doctype:
el = response.selector._root.getroottree().docinfo.doctype
item = DanishItem()
item['website'] = response
item['doctype'] = el
yield item
위대한 작품!내가 지금 알아낼 수없는 것만이 .json 파일에 응답을 15 번 작성하는 이유입니다. 위의 내용을 참조하십시오. –
답변에서 내 업데이트를 확인하십시오. – bosnjak
철저한 설명에 감사드립니다! 이것은 크게 작동합니다 :) –