Scrapy not finding table

好久不见. 提交于 2020-01-06 20:04:13

问题


I am trying to scrape data from the table in http://www.oddsportal.com/basketball/usa/nba-2014-2015/results/

The particular table I want has class="table-main"

running from scrapy response.xpath('//table')

In [28]:  response.xpath('//table')
Out[28]:
[<Selector xpath='//table' data=u'<table>\n\t\t\t\t\t\t\t\t<tr>\n\t\t\t\t\t<td c
lass="bol'>,
 <Selector xpath='//table' data=u'<table class="table-main top-event">\n\t\t\t'>
,
 <Selector xpath='//table' data=u'<table>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td>\n\t\
t\t\t\t\t\t<tab'>,
 <Selector xpath='//table' data=u'<table class="rm-bonus-offer">\n\t\t\t\t\t\t\t
\t<'>,
 <Selector xpath='//table' data=u'<table>\n\t\t\t\t\t<tr>\n\t\t\t\t\t\t<td>\n\t\
t\t\t\t\t\t<tab'>,
 <Selector xpath='//table' data=u'<table class="rm-bonus-offer">\n\t\t\t\t\t\t\t
\t<'>]

does not return the table I wish to scrape. Can anyone help?


回答1:


Simply use...

sel.xpath('.//table[starts-with(@class, "table-main")]')

or

sel.xpath('.//div[@id="top-event-box"]/table')



回答2:


I managed to get the table by response.xpath('//*[@id="tournamentTable"]')




回答3:


Selector(response).xpath('//table[contains(@class, "table-main")]').extract_first()

I've tested, it works.

See Selectors in scrapy doc



来源:https://stackoverflow.com/questions/33451060/scrapy-not-finding-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!