亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

python - 為什么用requests庫(kù)能爬取而用scrapy卻不能?

瀏覽:84日期:2022-09-08 13:31:18

問題描述

# -*- coding: utf-8 -*-import requestsdef xici_request(): url = ’http://www.xicidaili.com’ headers = {’Accept’: ’text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8’,’Accept-Encoding’: ’gzip, deflate, sdch’,’Accept-Language’: ’zh-CN,zh;q=0.8’,’Cache-Control’: ’max-age=0’,’Connection’: ’keep-alive’,’Host’: ’www.xicidaili.com’,’Referer’: ’https://www.google.com/’,’User-Agent’: ’Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36’ res = requests.get(url, headers=headers) print(res.text)if __name__ == ’__main__’: xici_request()

# -*- coding: utf-8 -*-import scrapyfrom collectips.items import CollectipsItemclass XiciSpider(scrapy.Spider): name = 'xici' allowed_domains = ['http://www.xicidaili.com'] headers = {’Accept’: ’text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8’, ’Accept-Encoding’: ’gzip, deflate, sdch’, ’Accept-Language’: ’zh-CN,zh;q=0.8’, ’Cache-Control’: ’max-age=0’, ’Connection’: ’keep-alive’, ’Host’: ’www.xicidaili.com’, ’Referer’: ’https://www.google.com/’, ’User-Agent’: ’Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36’} def start_requests(self):reqs = []for i in range(1, 21): req = scrapy.Request(’http://www.xicidaili.com/nn/{}’.format(i), headers=self.headers) reqs.append(req)return reqs def parse(self, response):item = CollectipsItem()sel = response.selectorfor i in range(2, 102): item[’IP’] = sel.xpath(’//*[@id='ip_list']/tbody/tr[{}]/td[2]/text()’.format(i)).extract() item[’PORT’] = sel.xpath(’//*[@id='ip_list']/tbody/tr[{}]/td[3]/text()’.format(i)).extract() item[’DNS_POSITION’] = sel.xpath(’//*[@id='ip_list']/tbody/tr[{}]/td[4]/a/text()’.format(i)).extract() item[’TYPE’] = sel.xpath(’//*[@id='ip_list']/tbody/tr[{}]/td[6]/text()’.format(i)).extract() item[’SPEED’] = sel.xpath(’//*[@id='ip_list']/tbody/tr[{}]/td[7]/p[@title]’.format(i)).extract() item[’LAST_CHECK_TIME’] = sel.xpath(’//*[@id='ip_list']/tbody/tr[{}]/td[10]/text()’.format(i)).extract() yield item

代碼如上,為什么requests能返回網(wǎng)頁(yè)內(nèi)容,而scrapy卻是報(bào)錯(cuò)內(nèi)部服務(wù)器錯(cuò)誤500? 請(qǐng)大神解救??

問題解答

回答1:

并發(fā)你沒考慮進(jìn)去吧,當(dāng)同一時(shí)間發(fā)起過多的請(qǐng)求會(huì)直接封你IP

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 亚洲精品图区 | 国产一及毛片 | 黄色网页观看 | 1024日本 | 欧美日韩一区二区三区自拍 | 四虎东方va私人影库在线观看 | 三级全黄a | 免费超爽大片黄 | 国产一区精品在线 | 久久久久夜色精品波多野结衣 | 亚洲成人黄色在线 | 黄色网址免费在线 | 未成人禁止视频高清在线观看 | 国产一二区视频 | 丁香狠狠色婷婷久久综合 | 精品视频免费在线 | 日韩欧美国产精品 | 久久99国产精品一区二区 | 日日摸夜夜夜夜夜添 | 久久亚洲国产最新网站 | 手机看片福利日韩欧美看片 | 欧美一区二区三区在线观看免费 | 午夜国产精品无套 | 456亚洲人成影院在线观 | 久久成人国产精品 | 国产伦精品一区二区三区无广告 | 青草资源视频在线高清观看 | 午夜视频在线观看一区 | 亚洲经典在线 | 亚洲午夜视频在线观看 | 亚洲一区二区中文 | 露脸真实国产精品自在| 久久国产乱子免费精品 | 一级毛片特级毛片免费的 | 国产美女精品在线 | 久久99精品久久久久久h | 精品国产一区在线观看 | 久久综合网久久综合 | xxxporn日本护士24 | 亚洲免费精品视频 | 欧美日一区 |