Scrapy not finding table

2019-09-14 15:37发布

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?

3条回答
Root(大扎)
2楼-- · 2019-09-14 16:03

Simply use...

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

or

sel.xpath('.//div[@id="top-event-box"]/table')
查看更多
不美不萌又怎样
3楼-- · 2019-09-14 16:11

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

查看更多
姐就是有狂的资本
4楼-- · 2019-09-14 16:16
Selector(response).xpath('//table[contains(@class, "table-main")]').extract_first()

I've tested, it works.

See Selectors in scrapy doc

查看更多
登录 后发表回答