Python Scrapy没有提取活动表数据,而是';他只是拉表代码?
您好,上面的代码假设是转到网站,逐行提取表数据,并将其作为纯文本写入文件。不幸的是,我不知道为什么,但当我使用爬虫时,值只是:Python Scrapy没有提取活动表数据,而是';他只是拉表代码?,python,scrapy,web-crawler,scrapy-spider,Python,Scrapy,Web Crawler,Scrapy Spider,您好,上面的代码假设是转到网站,逐行提取表数据,并将其作为纯文本写入文件。不幸的是,我不知道为什么,但当我使用爬虫时,值只是: from scrapy.spiders import Spider from tutorial.items import Table from scrapy.selector import Selector class GoalSpider(Spider): name = "stats" allowed_domains = ["numberfire.c
from scrapy.spiders import Spider
from tutorial.items import Table
from scrapy.selector import Selector
class GoalSpider(Spider):
name = "stats"
allowed_domains = ["numberfire.com"]
start_urls = ('http://www.numberfire.com/nba/fantasy/full-fantasy-basketball-projections', )
def parse(self, response):
hxs = Selector(response)
items = hxs.xpath('//td/text()')
with open("stats.txt", 'wb') as f:
for item in items:
f.write(item.extract() + ' || ')
for item in items:
my_item = Table()
my_item['tal'] = item.select('.//text()').extract()
my_item['sep'] = item.select('.//text()').extract()
yield my_item
我相信我正确地分离了它,但我不明白为什么爬虫程序会这样拉表数据,这些是正确的行,而不是实际的数据本身。似乎正在提取的数据是表的代码,而不是实际数据。解析是正确的,这是该响应体上的真实信息,这是一个javascript呈现问题(您想要的数据来自不同的请求)@eLRuLL那么是否没有可能的方法获取此数据?当然有(浏览器正在执行此操作)您只需检查此数据附带的请求是否正确,请使用firebug(firefox)之类的工具或者只是在chrome上的开发者控制台来检查请求。如果你想模拟浏览器,你也可以使用selenium。我一直在四处搜索,但似乎找不到任何关于如何提取这些数据的帮助,我使用firebug尝试搜索请求,但我没有任何运气。老实说,我不确定我在寻找什么。看在firebug中的“网络->XHR”-
XHR
表示AJAX
${opponent.abbrev} || #${opponent_rank} || ${minutes} || ${pts} || ${fgm}-${fga} || ${ftm}-${fta} || ${p3m}-${p3a} || ${treb} || ${ast} || ${stl} || ${blk} || ${tov} || ${pf} || ${fp} || $${salary} || ${ratio} ||