小编use*_*058的帖子

使用tor与scrapy框架

我正在尝试抓取网站,它足够复杂以阻止机器人,我的意思是它只允许一些请求,在Scrapy挂起之后.

问题1:有没有办法,如果Scrapy挂起,我可以从同一点重新开始我的爬行过程.为了摆脱这个问题,我写了这样的设置文件

BOT_NAME = 'MOZILLA'
BOT_VERSION = '7.0'

SPIDER_MODULES = ['yp.spiders']
NEWSPIDER_MODULE = 'yp.spiders'
DEFAULT_ITEM_CLASS = 'yp.items.YpItem'
USER_AGENT = '%s/%s' % (BOT_NAME, BOT_VERSION)

DOWNLOAD_DELAY = 0.25
DUPEFILTER=True
COOKIES_ENABLED=False
RANDOMIZE_DOWNLOAD_DELAY=True
SCHEDULER_ORDER='BFO'
Run Code Online (Sandbox Code Playgroud)

这是我的计划:

class ypSpider(CrawlSpider):

   name = "yp"


   start_urls = [
       SOME URL

   ]
   rules=(
      #These are some rules
   )
   def parse_item(self, response):
   ####################################################################
   #cleaning the html page by removing scripts html tags    
   #######################################################
   hxs=HtmlXPathSelector(response)
Run Code Online (Sandbox Code Playgroud)

问题是我可以编写http代理的地方,并且我必须导入任何与tor相关的类,我是Scrapy的新手因为这个小组我学到了很多东西,现在我正在努力学习"如何使用ip rotation or tor"

正如我们的一位成员建议的那样,我开始使用和设置HTTP_PROXY

set http_proxy=http://localhost:8118
Run Code Online (Sandbox Code Playgroud)

但是它会抛出一些错误,

failure with no frames>: class 'twisted.internet.error.ConnectionRefusedError'   Connection was refused …
Run Code Online (Sandbox Code Playgroud)

python tor scrapy

6
推荐指数
1
解决办法
6835
查看次数

使用XPath,Python和Scrapy解析HTML

我正在写一个Scrapy程序来提取数据.

这是网址,我想抓取20111028013117(代码)信息.我从FireFox附加XPather中获取了XPath .这是路径:

/html/body/p/table/tbody/tr/td/table[2]/tbody/tr[1]/td/table[3]/tbody/tr/td[2]/table[1]/tbody/tr/td/table/tbody/tr/td[2]/table[3]/tbody/tr/td/table/tbody/tr[2]/td[2]
Run Code Online (Sandbox Code Playgroud)

虽然我正在尝试执行此操作

try:
    temp_list = hxs.select("/html/body/p/table/tbody/tr/td/table[2]/tbody/tr[1]/td/table[3]/tbody/tr/td[2]/table[1]/tbody/tr/td/table/tbody/tr/td[2]/table[3]/tbody/tr/td/table/tbody/tr[2]/td[2]").extract()
    print "temp_list:" + str(temp_list)
except:
    print "error"
Run Code Online (Sandbox Code Playgroud)

它返回一个空列表,我很难在过去的4个小时内找到答案.我是scrapy的新手,尽管我为其他项目处理的问题非常好,但似乎有点困难.

python xpath scrapy

3
推荐指数
1
解决办法
2756
查看次数

标签 统计

python ×2

scrapy ×2

tor ×1

xpath ×1