所以我试着在这一页整理一下时间表。。http://stats.swehockey.se/ScheduleAndResults/Schedule/3940
…用这个代码。在
from scrapy.spider import BaseSpider
from scrapy.selector import HtmlXPathSelector
class SchemaSpider(BaseSpider):
name = "schema"
allowed_domains = ["http://stats.swehockey.se/"]
start_urls = [
"http://stats.swehockey.se/ScheduleAndResults/Schedule/3940"
]
def parse(self, response):
hxs = HtmlXPathSelector(response)
rows = hxs.select('//table[@class="tblContent"]/tbody/tr')
for row in rows:
date = row.select('/td[1]/div/span/text()').extract()
teams = row.select('/td[2]/text()').extract()
print date, teams
我不能工作,但是我不能工作。我做错什么了?我已经花了几个小时想弄清楚自己,但是我不知道为什么XPath不能正常工作。在
两个问题:
tbody
是现代浏览器添加的标记。Scrapy在html中根本看不到它。数据和团队的xpath是不对的:应该使用相对xpath(
.//
),td索引也是错误的,应该是2和3,而不是1和2以下是整个代码和一些modidications(工作):
希望有帮助。在
相关问题 更多 >
编程相关推荐