मुझे स्केपर का उपयोग कर वेबसाइटों से पीडीएफ फ़ाइलों को खींचने के लिए काम सौंपा गया है। मैं पाइथन के लिए नया नहीं हूं, लेकिन स्केपर मेरे लिए बहुत नया है। मैं कंसोल और कुछ प्राथमिक मकड़ियों के साथ प्रयोग कर रहा हूं। मैंने पाया है और इस कोड को संशोधित किया गया है:किसी वेबसाइट से पीडीएफ फ़ाइलों को खोजने और डाउनलोड करने के लिए स्केपर का उपयोग
import urlparse
import scrapy
from scrapy.http import Request
class pwc_tax(scrapy.Spider):
name = "pwc_tax"
allowed_domains = ["www.pwc.com"]
start_urls = ["http://www.pwc.com/us/en/tax-services/publications/research-and-insights.html"]
def parse(self, response):
base_url = "http://www.pwc.com/us/en/tax-services/publications/research-and-insights.html"
for a in response.xpath('//a[@href]/@href'):
link = a.extract()
if link.endswith('.pdf'):
link = urlparse.urljoin(base_url, link)
yield Request(link, callback=self.save_pdf)
def save_pdf(self, response):
path = response.url.split('/')[-1]
with open(path, 'wb') as f:
f.write(response.body)
मैं
scrapy crawl mySpider
साथ आदेश पंक्ति पर इस कोड को चलाने के लिए और मैं वापस कुछ भी नहीं मिलता है। मैंने एक स्केपर आइटम नहीं बनाया क्योंकि मैं फ़ाइल को क्रॉल और डाउनलोड करना चाहता हूं, कोई मेटा डेटा नहीं। मैं इस पर किसी भी मदद की सराहना करता हूं।
आप लॉग साझा कर सकते हैं? – eLRuLL