ฉันกำลังพยายามดาวน์โหลดข้อมูลจาก gsmarena โค้ดตัวอย่างในการดาวน์โหลดข้อมูลจำเพาะ HTC one me มาจากไซต์ต่อไปนี้ "http://www.gsmarena.com/htc_one_me-7275.php" ตามที่กล่าวไว้ด้านล่าง:
ข้อมูลบนเว็บไซต์จัดอยู่ในรูปแบบตารางและแถวของตาราง ข้อมูลอยู่ในรูปแบบ:
table header > td[@class='ttl'] > td[@class='nfo']
ไฟล์ Items.py:
import scrapy
class gsmArenaDataItem(scrapy.Item):
phoneName = scrapy.Field()
phoneDetails = scrapy.Field()
pass
ไฟล์แมงมุม:
from scrapy.selector import Selector
from scrapy import Spider
from gsmarena_data.items import gsmArenaDataItem
class testSpider(Spider):
name = "mobile_test"
allowed_domains = ["gsmarena.com"]
start_urls = ('http://www.gsmarena.com/htc_one_me-7275.php',)
def parse(self, response):
# extract whatever stuffs you want and yield items here
hxs = Selector(response)
phone = gsmArenaDataItem()
tableRows = hxs.css("div#specs-list table")
for tableRows in tableRows:
phone['phoneName'] = tableRows.xpath(".//th/text()").extract()[0]
for ttl in tableRows.xpath(".//td[@class='ttl']"):
ttl_value = " ".join(ttl.xpath(".//text()").extract())
nfo_value = " ".join(ttl.xpath("following-sibling::td[@class='nfo']//text()").extract())
colonSign = ": "
commaSign = ", "
seq = [ttl_value, colonSign, nfo_value, commaSign]
seq = seq.join(seq)
phone['phoneDetails'] = seq
yield phone
อย่างไรก็ตาม ฉันจะถูกแบนทันทีที่ฉันพยายามโหลดหน้าใน scrapy shell โดยใช้:
"http://www.gsmarena.com/htc_one_me-7275.php"
ฉันได้ลองใช้ DOWNLOAD_DELAY = 3 ใน settings.py แล้ว
กรุณาแนะนำฉันควรทำอย่างไร