【发布时间】:2014-09-14 02:59:38
【问题描述】:
我在练习Scrapy,想问一个问题:
我知道如何在课外使用 def printTW
当我在课堂上写它时如何调用它?
我的代码在这里:
请教我
from scrapy.spider import Spider
from scrapy.selector import Selector
from yahoo.items import YahooItem
def printTW(original_line):
for words in original_line:
print words.encode('utf-8')
class MySpider(Spider):
name = "yahoogo"
start_urls = ["https://tw.movies.yahoo.com/chart.html"]
#Don't know how to calling this
#def printTW(original_line):
# for words in original_line:
# print words.encode('utf-8')
def parse(self, response):
for sel in response.xpath("//tr"):
movie_description = sel.xpath("td[@class='c3']/a/text()").extract()
printTW(movie_description)
【问题讨论】:
标签: python python-2.7 scrapy