本文整理匯總了Python中spider.Spider.add_request方法的典型用法代碼示例。如果您正苦於以下問題:Python Spider.add_request方法的具體用法?Python Spider.add_request怎麽用?Python Spider.add_request使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類spider.Spider
的用法示例。
在下文中一共展示了Spider.add_request方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Spider
# 需要導入模塊: from spider import Spider [as 別名]
# 或者: from spider.Spider import add_request [as 別名]
sys.exit(0)
conn = MySQLdb.connect(host=config.db_host,
user=config.db_user,
passwd=config.db_password,
db=config.db_database,
charset='utf8')
cursor = conn.cursor()
cursor.execute('select configValue from t_spider_config where configKey=%s',
(arg_config.get(sys.argv[1]),))
config_values = [row[0] for row in cursor.fetchall()]
if sys.argv[1] == 'paper':
spider_paper = Spider('paper')
for search_exp in config_values:
reqs = parser.paper_page_parser(search_exp)[:500]
for req in reqs:
spider_paper.add_request(req)
spider_paper.crawl()
if sys.argv[1] == 'news':
spider_news = Spider('news')
for seed_url in config_values:
spider_news.add_request(Request(arg=seed_url,
parser=parser.news_parser))
spider_news.crawl()
if sys.argv[1] == 'patent':
spider_patent = Spider('patent')
for search_exp in config_values:
spider_patent.add_request(Request(arg=search_exp,
parser=parser.patent_parser))
spider_patent.crawl()