问题
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